I am trying to supply constraints to a a function minimisation that I have hitherto been performing successfully with an unconstrained algorithm available via scipy (scipy.optimize.fmin_l_bfgs_b()
).
Reading up (see, e.g, Python constrained non-linear optimization), I discovered a minimisation packed called mystic
that seems to be what I need. My situation is as follows. I have a function of 3N
variables (representing xyz position coordinates of N
nodes), and I want to supply a list of constraints such that z/x = const.
for each node. This makes for a total of N
constraints. How do I do define/supply these constraints most efficiently for mystic()
? Can the same constraint object be used with scipy.optimize.slsqp()
as well? Since my constraints are linear, this should be a viable option too.
I tried the following, but it crashed my computer:
import mystic.symbolic as ms
ieqns = ''
for p in range(N):
ieqns += 'x'+str(p+2) +'/x'+str(p) +" <= 2"
cf = ms.generate_constraint(ms.generate_solvers(ms.simplify(ieqns)))
pf = ms.generate_penalty(ms.generate_conditions(ieqns), k=1e12)