I'm trying to make biggest ellipse inside arbitrary polygon.
So, I made the equation of ellipse and constraint .
objective : minimize A*B (mimimaze 1/area)
st. A**2*(x-x0)**2+B**2*(y-y0)**2 = 0
x/100.0 + y/80.0 < 1
x/-20.0 + y/80.0 < 1
x/-40.0 + y/-40.0 > 1
x/100.0 + y/-60.0 > 1
then I made optimization code using Scipy like below But my code makes False result. (Success : False). Can you explain why my code cannot make successful result? due to false constraint? wrong coding? Note that I don't need tilted ellipse.
import numpy as np
from scipy.optimize import minimize
def objective(C):
A = C[0] ; B = C[1] ; x0 = C[2] ; y0 = C[3] ; x = C[4] ; y = C[5]
return A*B
def constraint1(C):
A = C[0] ; B = C[1] ; x0 = C[2] ; y0 = C[3] ; x = C[4] ; y = C[5]
return (x/100.0+y/80.0-1)*-1
def constraint2(C):
A = C[0] ; B = C[1] ; x0 = C[2] ; y0 = C[3] ; x = C[4] ; y = C[5]
return (x/-100.0+y/80.0-1)*-1
def constraint3(C):
A = C[0] ; B = C[1] ; x0 = C[2] ; y0 = C[3] ; x = C[4] ; y = C[5]
return (x/-100.0+y/-80.0-1)*-1
def constraint4(C):
A = C[0] ; B = C[1] ; x0 = C[2] ; y0 = C[3] ; x = C[4] ; y = C[5]
return (x/100.0+y/-80.0-1)*-1
def constraint5(C):
A = C[0] ; B = C[1] ; x0 = C[2] ; y0 = C[3] ; x = C[4] ; y = C[5]
return A**2*(x-x0)**2+B**2*(y-y0)**2-1
xeval = [1,1,0,0,0,0]
bnds = ( (0.001,1),(0.001,1),(-100,100),(-100,100),(-500,500),(-500,500) )
con1 = {'type': 'ineq','fun':constraint1}
con2 = {'type': 'ineq' , 'fun':constraint2}
con3 = {'type': 'ineq','fun':constraint3}
con4 = {'type': 'ineq' , 'fun':constraint4}
con5 = {'type': 'eq' , 'fun':constraint5}
cons = [con1,con2,con3,con4,con5]
sol = minimize(objective,xeval,method='SLSQP',bounds=bnds,constraints=cons)