1
$\begingroup$

Setup

I have a non-empty set of elements $U$ that are arranged spatially.

I would like to partition $U$ into $N$ non-empty, disjoint subsets, $A_i$, having up to $M$ elements each. Each subset is only allowed to contain neighboring elements.

I would like to also partition $U$ into $N$ non-empty, disjoint subsets, $B_j$, having up to $M$ elements each. Each subset is only allowed to contain neighboring elements.

Finally, I'd like to require that for every subset $A_i$, and $B_j$ that $\lvert A_i \cap B_j \rvert = 1$.

Concrete example

Consider a 3 x 3 grid of elements. The first partition would consist of one subset for each row. The second partition would consist of one subset for each column. Every element would then only exist in exactly one subset of each partition.

This is of course not the only solution. One could have a partition consisting of the upper left three elements, antidiagonal elements and lower-right three elements. The second partition would then consist of the top right three elements, diagonal elements, and lower left three elements.

My goal

  1. I would like to identify a process where I provide the set $U$ and parameter $M$ and the first and second partitions are produced.

  2. As a modification to that first goal, to find an optimal partition that minimizes the aggregate distance between elements within all subsets.

My intuition is that this is a variant of set cover, and could be modeled via ILP, but I want to open this up to get other opinions on how to approach this.

Clarifications

  1. What do you mean by "Each subset is only allowed to contain neighboring elements"?

Every element in the subset is within a fixed distance of at least one other element in the subset. Assume some distance metric to measure distance.

  1. What do you mean by "the aggregate distance between elements within all subsets"?

Given the elements in a subset, construct a weighted complete graph. Each edge has weight equal to the distance between the elements. Find the minimum spanning tree. Take the sum of the edges. Call that $d(S)$.

Goal is to minimize $\sum_i d(A_i) + \sum_j d(B_j)$

$\endgroup$
5
  • $\begingroup$ Add clarifications. Nearest was corrected to neighboring. $\endgroup$
    – user155171
    Commented Nov 11, 2022 at 21:52
  • $\begingroup$ Got it. Do you have a typical size for $n$ and $m$? $\endgroup$
    – D.W.
    Commented Nov 11, 2022 at 22:02
  • $\begingroup$ $\lvert U \rvert = 2^a$, $N = 2^{a/2}$, $M \le N$. $\endgroup$
    – user155171
    Commented Nov 12, 2022 at 0:24
  • $\begingroup$ And what's a typical size for $a$? $\endgroup$
    – D.W.
    Commented Nov 12, 2022 at 2:35
  • $\begingroup$ Typically $a > 5$. $\endgroup$
    – user155171
    Commented Nov 12, 2022 at 17:16

1 Answer 1

0
$\begingroup$

For part 1, another approach is to use a SAT solver. This might be slightly faster than an ILP solver.

Let the boolean variable $a_{v,i}$ be true if $v \in A_i$, and $a_{v,i}$ be true if $v \in B_i$. Then you obtain some constraints (CNF clauses) as follows:

  • The $A_i$'s form a partition: $\neg a_{v,i} \lor \neg a_{v,j}$ for all $i\ne j$, $\lor_i a_{v,i}$ for all $v$. Do the same for the $B_i$'s. (Or see Encoding 1-out-of-n constraint for SAT solvers for more compact encodings.)

  • Only neighboring elements: $\neg a_{v,i} \lor \neg a_{w,i}$ for all $v,w$ that aren't neighboring. Same for the $b$'s.

  • Limited size: use an "at most $M$" constraint to ensure that, for each $i$, at most $M$ of $a_{v,i}$ are true. See Reduce the following problem to SAT.

  • Overlap: for each pair $i,j$, we have $\lor_v (a_{v,i} \land b_{v,j})$, and we also have $\neg a_{v,i} \lor \neg a_{w,i} \lor \neg b_{v,j} \lor \neg b_{w,j}$ for all $v \ne w$. (Or see Encoding 1-out-of-n constraint for SAT solvers for more compact encodings.)

If you use Z3, many of these can be expressed more effectively using pseudo-boolean constraints.

Solving your part 2 with a SAT solver looks messy, so for part 2, ILP looks like a better fit.

$\endgroup$
1
  • $\begingroup$ Makes sense. I could use SAT to propose candidate partitions and maybe use a modified Kernighan–Lin to bridge the gap towards part 2. Thanks for taking the time to share your thoughts and write this up. $\endgroup$
    – user155171
    Commented Nov 12, 2022 at 0:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.