4

I am doing some modelling where I am trying to randomly layout some points on a grid. What I know:

  • How big the grid is
  • The number of objects that have to be laid out on the grid, at a point
  • The minimum distance between one point to another
  • The distance between points on a grid

I am reasonably certain that the constraints that I have will not produce a correct result, but without either calculating that isn't possible through iteration or some other means, I don't think I can prove this.

I have code which solves this given certain constraints, but I'm trying to figure out a way where I can calculate the number of possibilities (if any) for some given constraints, or if indeed, the given constraints have no solution.

My code currently keeps trying random points within the grid until either a valid set of points are found, or there are no more points to try.

Thanks for your help.

H2OBorne
  • 43
  • 4
  • Welcome to Mathematica.SE! I suggest that: 1) You take the introductory Tour now! 2) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! 3) As you receive help, try to give it too, by answering questions in your area of expertise. – bbgodfrey Apr 17 '15 at 20:13
  • 2
    I encourage you to include in your question the code that you have written to attempt to solve this problem, even if it is not working. Doing so will increase the chances of useful responses from readers. – bbgodfrey Apr 17 '15 at 20:15
  • Is your grid a Cartesian grid? Is your distance metric Euclidean, or for instance a Manhattan metric? – kirma Apr 17 '15 at 20:53
  • @kirma yes, it is a Cartesian grid, and the distance metric is Euclidean – H2OBorne Apr 17 '15 at 23:11

1 Answers1

5

Consider a 10x10 Cartesian grid with grid position spacing of 1. 15 points are laid on this grid, with requirement of Cartesian distance greater than 2 between two points. How many layouts there can be?

I consider every grid point a Boolean variable, and prohibit all point pairs which don't satisfy the minimum distance constraint. In addition to this, I require precisely 15 true values to be present using BooleanCountingFunction. I feed the resulting Boolean equation to SatisfiabilityCount which computes number of possible solutions without checking all of them separately:

With[{pts = Flatten[Table[{x, y}, {x, 10}, {y, 10}], 1]},
 SatisfiabilityCount[
  BooleanCountingFunction[{15}, Length@pts] @@ (p /@ pts) && 
   And @@ (! (p@#1 && p@#2) & @@@ 
      Select[Subsets[pts, {2}], EuclideanDistance @@ # <= 2 &])]]

21888441964

For smaller grids, it's also possible to find the solutions in reasonable time:

With[{pts = Flatten[Table[{x, y}, {x, 8}, {y, 8}], 1]},
 MatrixPlot@Boole@Partition[#, 8] & /@ 
  SatisfiabilityInstances[
   BooleanCountingFunction[{6}, Length@pts] @@ (p /@ pts) && 
    And @@ (! (p@#1 && p@#2) & @@@ 
       Select[Subsets[pts, {2}], EuclideanDistance @@ # <= 4 &]), 
   p /@ pts, All]]

enter image description here

kirma
  • 19,056
  • 1
  • 51
  • 93