python - Complex scipy optimization with shared values across constraints -


i'm trying implement structural optimization code using python , scipy.optimize library. objective minimize weight of structure, , there 5 inequality constraints various material stresses , failure conditions. plan use either cobyla or slsqp methods.

i've done few optimization codes using scipy in past, simple functions of design variables (much tutorials in official scipy docs). can't seem wrap head around problem of constraint functions codependent.

i created class contains bunch of extraneous data (material properties, loads, constant geometry parameters, helper functions...) passed argument objective function , constraint functions. question revolves around when call helper function calculates several parameters used evaluate constraints.

  • when scipy.optimize passes external arguments objective , constraint functions, single instance of object? or make n copies each function?

  • does optimize module evaluate constraints before evaluating objective function?

  • does optimize module evaluate constraints in parallel or go sequentially through them 0 n?

  • can call helperclass.updatesharedvalues() once (for example, in either first constraint function or in objective function) , have new values accessible other constraint functions? or need call in every constraint function?

here's pseudo-code explain i'm doing:

""" inside main script calls scipy.optimize """ cons =({'type': 'ineq', 'fun': g0},        {'type': 'ineq', 'fun': g1},        {'type': 'ineq', 'fun': g2},        {'type': 'ineq', 'fun': g3},        {'type': 'ineq', 'fun': g4})  result = scipy.optimize.minimize(weight, x0, args =(helperclass),bounds = bnds,constraints = cons) 

a generalized example of objective function

def weight(x,arg):     helperclass = arg      # calculate current weight based on design parameters ,      # 10 other constants     w = dostuff(x, helperclass.somestuff1, helperclass.somestuff2,...)     return w 

a generalized example of constraint functions:

def g0(x,arg):     helperclass = arg      # call function calculates 10 other variables      # used 5 constraint functions     helperclass.updatesharedvalues(x)     g0 = dostuff(x,helperclass.value1,helperclass.value5)     return g0  def g1(x,arg):     helperclass = arg      # need calculate these values in every constraint function     # or can in first 1 , others have      # access updated values?     helperclass.updatesharedvalues(x)     g0 = dostuff(x,helperclass.value2,helperclass.value3)     return g1 


Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -