Skip to content

Instantly share code, notes, and snippets.

View jspalink's full-sized avatar

Jonathan Spalink jspalink

View GitHub Profile
@CnrLwlss
CnrLwlss / circleObjective.py
Created January 19, 2013 13:51
Functions for packing N circles into a rectangle of width W and height H, together with a function for plotting solution and some example code fitting 13 circles into a square. http://cnr.lwlss.net/CircleObjectivesPython/ #python #opimisation #circle #packing #svg #function #closure
import random, numpy
def genGuess(N,W,H):
'''Generate sensible initial guess vector (random circle coordinates and radii)'''
z=numpy.zeros(3*N)
for i in xrange(0,N):
z[i*3]=random.random()*W
z[i*3+1]=random.random()*H
z[i*3+2]=0.001*min(W,H)+random.random()*(0.009*min(W,H))
return(z)