For the no-three-in-line problem, it has been known since the 1990s that grids with have sets of points with no three in line. Those results, by Achim Flammenkamp, were based on custom search software and a lot of compute time. I was curious to see how far one could get with more-modern but generic optimization codes, so this weekend I ran a little experiment.
I think that in this area, most general-purpose solvers can be reasonably divided into two categories: integer linear program solvers, and satisfiability solvers. For the no-three-in-line problem, we have - integer variables ( if a point is included, if it is excluded), linear constraints (the sum of variables on any line should be at most ), and a linear optimization criterion (maximize the sum of variables). So this led me to look at integer linear program solvers rather than satisfiability solvers. Based on a comparison by Matt Strimas-Mackey, I chose Gurobi over several open-source alternatives. Gurobi is not open source, but it is free for academic purposes.
This was my first experience with an ILP solver, and my impression was that everything “just worked”. Gurobi was easy to download and install, easy to run, and easy to program following the model of their simple Python example in their Quick Start Guide.
On the other hand, although it worked quickly for small grids, it was far from being able to reach the grid sizes already solved by Flammenkamp. With the formulation of the problem that I used, the boundary between easy and difficult problems was between (five seconds to solve on my laptop) and (thirty minutes to solve). It’s important to remember, though, that this was my first attempt at coding up anything as an integer linear program, and my first time using this system. So it’s entirely likely that an expert user of the system would know some tricks that would let it get farther.
Perhaps it’s also important to remember that for it’s searching through a space of possible solutions, and for that blows up to approximately . So the fact that it can solve these at all, and do so relatively quickly, is quite impressive.
In case anyone else wants to try it, here’s my code:
It’s in Python 2 rather than Python 3 because somehow that’s the default for my installation (probably because it’s the default command-line python on my laptop). The code after the optimize step produces a picture of the solution in crude ASCII graphics. Here’s a prettier version of the solution: