Lindo Systems

! Pack spheres of radius 1.0 inside a cube of minimum volume.
   X(I), Y(I), Z(I) = coordinates of the center of sphere I.
   ;
! Keywords: Packing, sphere packing;
SETS:
 SPHERE: X, Y, Z;
 SXS(SPHERE, SPHERE)| &1 #LT# &2;
ENDSETS
DATA:
! Get the number of spheres;
 SPHERE = 1..6 ;
! 6 spheres requires a cube of length
   3.88562 on a side;
! Make sure global solver is enabled by clicking on:
 LINGO | Options | Global Solver | Use Global Solver;
ENDDATA

! Min the side size of the cube enclosing all the SPHEREs;
 MIN = RBIG;
! Each SPHERE of radius 1 must be inside the cube;
@FOR( SPHERE(I):
 [INXL] X(I) >= 1;
 [INXU] X(I) + 1 <= RBIG;
 [INYL] Y(I) >= 1;
 [INYU] Y(I) + 1 <= RBIG;
 [INZL] Z(I) >= 1;
 [INZU] Z(I) + 1 <= RBIG;
    );

! Spheres I and J cannot overlap;
@FOR( SXS(I,J):
 [NOVLAP] (X(I) - X(J))^2 + (Y(I) - Y(J))^2 + (Z(I) - Z(J))^2 >= (1+1)^2;
    );

 ! Get rid of some symmetry by numbering the
  spheres according to position on the X coordinate;
 @FOR( SPHERE(i) | i #GT# 1:
    X(i) >= X(i-1);
      );