def objfunc(x): inputs = {'sma':{'x-':x[0], 'y-':x[1], 'x+':x[2], 'y+':x[3]}, 'linear':{'x-':x[4], 'y-':x[5], 'x+':x[6], 'y+':x[7]}} DataFile = open('opt_data.txt','a') for x_i in x: DataFile.write( '\t %.5f' % (x_i) ) DataFile.close() # print inputs outputs = run(inputs = inputs, parameters = [eng]) k_nadir = 0 k_utopia = 514.486 normalized_theta = 1 + outputs['theta']/(math.pi/2.) normalized_k = (abs(outputs['k']) - k_nadir)/(k_utopia - k_nadir) f = 0.9*normalized_theta + 0.1*normalized_k DataFile = open('opt_data.txt','a') DataFile.write( '\t %.5f \t %.5f \t %.5f' % (outputs['theta'], outputs['k'], f) ) DataFile.write('\n') DataFile.close() # f = x[0] + x[1] + x[2] + x[3] + x[4] + x[5] + x[6] + x[7] fail = 0 g = [] return f,g,fail
def objfunc_BFGS(x): inputs = {'sma':{'x-':x[0], 'y-':x[1], 'x+':x[2], 'y+':x[3]}, 'linear':{'x-':x[4], 'y-':x[5], 'x+':x[6], 'y+':x[7]}} DataFile = open('opt_data.txt','a') for x_i in x: DataFile.write( '\t %.5f' % (x_i) ) DataFile.close() # print inputs outputs = run(inputs = inputs, parameters = [eng]) f = outputs['theta'] # print f DataFile = open('opt_data.txt','a') DataFile.write( '\t %.5f' % (f) ) DataFile.write('\n') DataFile.close() return f