
from com.cureos.numerics import Cobyla,Calcfc
from java.lang import Math

nvar=9         # number of variables
nconst=14      # number of constraints
rhobeg=0.5     # Initial size of the simplex 
rhoend=1.0e-10 # Final value of the simplex 
iprint = 0     # no output to Std.Out
maxfun = 5000  # Maximum number of function evaluations before terminating 
     
class calFun(Calcfc):           
  def Compute(self, n, m, x, con):
                con[0] = 1.0 - x[2] * x[2] - x[3] * x[3];
                con[1] = 1.0 - x[8] * x[8];
                con[2] = 1.0 - x[4] * x[4] - x[5] * x[5];
                con[3] = 1.0 - x[0] * x[0] - Math.pow(x[1] - x[8], 2.0);
                con[4] = 1.0 - Math.pow(x[0] - x[4], 2.0) - Math.pow(x[1] - x[5], 2.0);
                con[5] = 1.0 - Math.pow(x[0] - x[6], 2.0) - Math.pow(x[1] - x[7], 2.0);
                con[6] = 1.0 - Math.pow(x[2] - x[4], 2.0) - Math.pow(x[3] - x[5], 2.0);
                con[7] = 1.0 - Math.pow(x[2] - x[6], 2.0) - Math.pow(x[3] - x[7], 2.0);
                con[8] = 1.0 - x[6] * x[6] - Math.pow(x[7] - x[8], 2.0);
                con[9] = x[0] * x[3] - x[1] * x[2];
                con[10] = x[2] * x[8];
                con[11] = -x[4] * x[8];
                con[12] = x[4] * x[7] - x[5] * x[6];
                con[13] = x[8];
                return -0.5 * (x[0] * x[3] - x[1] * x[2] + x[2] * x[8] - x[4] * x[8] + x[4] * x[7] - x[5] * x[6]);

x = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]  # initial values of the variables
cc=Cobyla()
result=cc.FindMinimum(calFun(), nvar, nconst, x, rhobeg, rhoend, iprint, maxfun); 
print  cc.getOutput().tolist()
