4

I would like to find $\{0,1\}$-solutions of a system of equations of the form $$\left\{\begin{array}{c}\sum_{i\in I_1}x_i=1\\\sum_{i\in I_2}x_i=1\\\vdots\\\sum_{i\in I_k}x_i=1\end{array}\right.$$

where $x_1,\ldots,x_n\in\{0,1\}$ are the variables and $I_1,I_2,\ldots,I_k$ are given subsets of $\{1,2,\ldots,n\}$.

I have now been solving this system by reducing its matrix over $\mathbb{Q}$ and then iterating over all possible combinations for the free variables in $\{0,1\}$, and verifying if the other variables are also in $\{0,1\}$ then. However that is likely not the best way. So my questions:

  1. Several people have mentioned that "Lattice base reduction" provides a good solution to this. Unfortunately, when looking that up, I fail to see how that would make this system of equations easier to solve. What is the link?
  2. Are there any other methods that I should be aware of for solving this kind of problems? Bonus points if not all constant coefficients have to be $1$, then I could add a few more equations to reduce my search space.
Dang Dang
  • 320

3 Answers3

0

Your equation system (coefficients, right hand side, variables are all Boolean) has the structure of an exact cover problem. Based on Algorithm X, there are specialized solvers for this problem, most prominently Donald Knuth's dancing links, and his newer version dancing cells, where the data structure got adjusted to better fit modern processor architecture.

For implementations, look for DLX (dancing links) and SSXCC (dancing cells) Knuth's homepage. Another implementation of dancing links is libexact.

With very high chance, these algorithms will be much faster than any LLL based approach. However, when coefficients / boundaries for variables in your Diophantine linear equation system are larger, LLL is usually the way of choice.

azimut
  • 24,316
  • The link you provided to knuths page or to libexact does not give the user access to software which is useable for a non-C programmer. The Knuth link also requires experience with the obscure CWEB file format and build tools. libexact only the latter. It is not obvious that these academic and rarely maintained pieces of software are at all competitive with industrial strenght MILP or SAT solver both of which open one up to a variety of algorithms and portability. I could not find any work benchmarking Knuths widely admired algorithm with different approaches. – worldsmithhelper May 14 '25 at 10:00
  • @worldsmithhelper For the exact cover problem, the dancing links approach is the algorithm of your choice, and in typical instances it is much faster than using a MILP or SAT solver. Concerning your difficulties in using the software: I'm sorry, but these links are the best I'm aware of. – azimut May 14 '25 at 16:18
  • @worldsmithhelper From https://math.stackexchange.com/help/privileges/vote-down "When should I vote down? [...] Downvote answers that are incorrect or don't provide sufficient information to be useful in answering the question. Some answers may not attempt to answer the question at all, and should be flagged." --- it should be pretty clear that my answer does not qualify for that criterion. Please remove your downvote. – azimut May 14 '25 at 16:22
  • I do not see that advice being useful for most people as that software is a pain to get installed. I am not even sure if the most popular desktop OS (Windows) is is supported. This is a problem with your suggest solution, as such i find my down vote reasonable. – worldsmithhelper May 14 '25 at 16:57
  • @worldsmithhelper Come on, that is ridiculous. And no, your downvote is not reasonable. Sorry. – azimut May 14 '25 at 17:00
  • If you modify your answer so you point to an implementation which can be installed without much pain on the major operating system and document the input format that program expects in so far it is non standard then i agree that the answer would be useful and you'd even get an upvote. – worldsmithhelper May 14 '25 at 17:12
  • @worldsmithhelper No, I won't bother. In the end, I'm answering the OP's question (which did not ask for links to insta-usable programs, and which should be the base for evaluating my answer), and not your special requests. Also, note that we are on math.stackexchange and not on a Windows luser forum. – azimut May 14 '25 at 17:18
0

Your question is very similar to Sudoku type of problems.

Sudoku puzzles can be reduced to the system of equations that has the same structure as yours. In Sudoku puzzles, there should be one and only one 1 in each row, column and box; there should be one and only one 2 in each row, column and box etc. You can write these conditions as a system above. Let $x_{n, r, c}$ be 1 if the number $n$ is in row $r$, column $c$, and $0$ otherwise; $n, r, c$ $\in$ $\{1, 2, \dots, 9\}$. You will have 3 types of subsets.
The row equations are: $\forall r, n \in \{1, 2, \dots, 9\}$ will correspond to subsets $$ I_{r, n} = \bigcup_{\forall c \in \{1, \dots, 9\}} \{n, r, c\}$$ Column equations are: $\forall c, n \in \{1, 2, \dots, 9\}$ will correspond to subsets $$ I_{c, n} = \bigcup_{\forall r \in \{1, \dots, 9\}} \{n, r, c\}$$ Finally, box equations are: $\forall R, C \in \{0, 3, 6\}, n \in \{1, 2, \dots, 9\}$ will correspond to subsets $$ I_{R, C, n} = \bigcup_{\forall r, c \in \{1, 2, 3\}} \{n, R + r, C + c\}$$

All sudoku algorighm I have seen can be used for general problem - the one you state above. See http://en.wikipedia.org/wiki/Sudoku_solving_algorithms and http://www.math.cornell.edu/~mec/Summer2009/meerkamp/Site/Solving_any_Sudoku_II.html among others. Just replace "rows, columns and boxes" by "sets $I_\cdot$", and you can apply them right away. And, I believe, right hand equation values can be different from 1, still, the same algorithms will apply.

Hope this helps!

Yulia V
  • 1,450
  • Thanks! That second link seems to give an error though: Forbidden

    You don't have permission to access /~mec/Summer2009/meerkamp/Site/Solving_any_Sudoku_II.html on this server.

    – user1111929 Sep 30 '14 at 18:35
  • 1
    It was working a few minutes ago, and Solutions part I still works (http://www.math.cornell.edu/~mec/Summer2009/meerkamp/Site/Solving_any_Sudoku_I.html) Hopefully this link will resuscitate soon. Usual googling "sudoku algorithms" will yield many more options, if you need them. – Yulia V Sep 30 '14 at 18:38
  • This comment is entirely super seeded by the exact cover comment as that classifies the problem family accurately. It does not contribute any additional insight. – worldsmithhelper May 14 '25 at 09:33
  • @worldsmithhelper Just because other answers might provide more/more general/better information, this doesn't justify a downvote, see https://math.stackexchange.com/help/privileges/vote-down – azimut May 14 '25 at 17:56
-1

To elaborrate on the "Lattice base reduction". Given a system where $a_{n,m} \in \mathbb{R}$

$$\left\{\begin{array}{c}\sum_{i\in I_1} a_{1,i} x_i=1\\\sum_{i\in I_2}a_{2,i} x_i=1\\\vdots\\\sum_{i\in a_{k,i} I_k}x_i=1\end{array}\right.$$

Latice basis reduction will give you $k$ different nearly orthogonal vectors whose integer weighted combinations give you the entire lattice. In your case, you have an additional constraint $x_i \in \{0,1\}$. This implies the constraint $0 \leq x_i \leq 1$. However lattices can not contain inequalities. Thus a lattice approach is not appropriate or helpful.

When being faced with such a problem i would trust a mature, competitve software package which (not to cast shade at Donald Knuth) is developed by large group of people and used by a large group of people. There are specialized solver for this "exact-cover" type of problem matching that criteria.

However for flexibilities sake i'd encourage you to use a more general language called Mixed-Integer Linear Programming, which are able to solve and optimize arbitrary linear inequalities involving integers and real numbers. This will also allow you to express logical constraints if that helps in your application.

Software packages i can recommend for that are:

  • Gurobi, which is a commercial solver but has some licensing options which might work for you.
  • SCIP, which is a free open source solver
  • HiGHS, which is a free open source solver

All of those should be able detect (some(?) of) the special structure of the problem and exploit it. What is nice about them is these competing software packages share an underlying mathematics and can be fed using the same modeling languages such as JuMP and input formats like the .nl file format.

It could also be that Google's OR-Tools handles those problems well but this uses a different paradigm.

  • I can only repeat myself: For typical exact cover problems, the dancing links approach is much faster than a general purpose MILP or SAT solver. – azimut May 14 '25 at 16:24
  • If you have any evidence to that effect please contribute to this question: https://cs.stackexchange.com/questions/171918/is-knuths-dancing-cells-xcc-solver-competitive-against-sat-milp-csp-solvers-for Still there are many advantages to going with MILP/SAT based on the sorrounding tooling. Such as computing an Irreducible Infeasible Subsystem which is great for debugging modeling errors, community support, widely tested software, proof logging, ... All of these are options one doesn't have with dancing links approaches. If it is fast enough to solve via MILP/SAT then that's the better choice. – worldsmithhelper May 14 '25 at 17:04
  • I'm sure about that point, from personal experience with large exact cover problems. A quick internet search revealed http://www.slabbe.org/blogue/2018/12/comparison-of-wang-tiling-solvers/ which the same tendency. – azimut May 14 '25 at 17:21