How to pack n equal disks(radius a/2) with maximal area inside a given rectangle ?
I'm trying to solve this problem using Mathematicas Region functions.
Here my approach:
Maximize the area of the union of all disks regK
and require all disks to lie inside the square RegionWithin[rect,regK]
.
sys[a_?NumericQ, pts_ ?(MatrixQ[#, NumericQ] & )]:=Block[{
rect = Rectangle[{-1/2, -1/2}, {1/2, 1/2}],
regK = RegionUnion[Map[Disk[#, a/2] &, pts]]}
,
{ Area[regK],
Join[{RegionWithin[rect, regK] , 0 < a < 1/2},
Map[-1/2 < # < 1/2 &, Flatten[ pts]]]}]
Unfortunately
n=3; (*number of circles*)
NMaximize[ sys[a, Table[{x[i], y[i]}, {i, 1, n}]]
, Join[{a}, Flatten[Table[{x[i], y[i]}, {i, 1,n}]]]]
(*NMaximize::nnum: The function value {-0.835066,{-False,-False,-False,-True,-False,-True,-False,-False}}
is not a number at
{a,x[1],x[2],x[3],y[1],y[2],y[3]} = {0.677613,0.614816,0.51572,0.66946,-0.0824906,0.251149,0.6107}.*)
NMaximize
stops evaluation with an error message.
What's wrong with my code? Thanks!
a
fixed in "radiusa/2
maximal"? $\endgroup$a/2
. $\endgroup$