Global Optimization in Python on a 3D (or four dimensional) array

100 views Asked by At

I am trying to optimize a three-dimensional (or four-dimensional) array using the SciPy library for Python. I am currently using the DIRECT (Dividing Rectangles) method. The goal here is to get as close to zero as possible. What I am noticing is that the result for a single-dimension array is much closer to the global optimum than the result for a 3D array. I find the value of 9 to be unacceptably far from zero, which is what a 3D bounds array produces.

The test case code below doesn't perform any operations -- the 'fitness' function just spits back the random number selected by the optimizer. How can I reliably using a global optimization algorithm where there are more than 2D variables (x,y,), if I also need to use z in order to optimize the position of a brick in 3D space? The application for this optimization consists of a 3D tetris like problem of using bricks and brick chunks to build a wall.

# r: scipy
import scipy 


def fitnessOfBrick(bounds):

    print('testing',bounds[0])
    return bounds[0]

#bounds =     [[0,503],[0,101],[0,102]] #3d array
 bounds =     [[0,503],[0,101]] #2d array

print(bounds)

result = scipy.optimize.direct(

    fitnessOfBrick, bounds, eps=20, maxiter=4000, maxfun=6000, f_min=0, f_min_rtol=0.1

)

print('Status : %s' % result['message'])
print('Total Evaluations: %d' % result['nfev'])

solution = result['x']
evaluation = fitnessOfBrick(solution)

print('Solution: f(%s) = %.5f' % (solution, evaluation))

Output with 2D array:

testing 17.59465020576133
testing 17.59465020576133
Status : Number of function evaluations done is larger than maxfun=6000
Total Evaluations: 6001
testing 1.0349794238683263
Solution: f([  1.03497942 100.37654321]) = 1.03498

Output with 3D array:

testing 121.0925925925926
testing 121.0925925925926
Status : Number of function evaluations done is larger than maxfun=6000
Total Evaluations: 6001
testing 9.314814814814829
Solution: f([ 9.31481481 50.5        96.33333333]) = 9.31481

What I am trying to develop is a way to automatically position recycled brick (demolition brick chunks) to construct a wall for an architecture/construction class using robotic arms.

A video of this process done semi-manually (please note the different sizes of the brick chunks): brick wall building using galapagos in grasshopper - evolutionary solver

brick chunks

0

There are 0 answers