3

Hi I am doing a minimization problem and I wanted to try the 'trust-constr' method, with scipy function optimize.minimize, to compare it with the 'SLSQP' results. Unfortunatly I don't know why when I set my method to 'trust-constr', it tells me that :

ValueError: constraint of an unknown type is passed.

The code is the following:

con1 = {'type':'eq', 'fun': eq2}
con2 =  {'type':'ineq', 'fun' : ieq_bck2}
con3 =  {'type':'ineq', 'fun' : ineq_rb2}
con4 =  {'type':'ineq', 'fun' : ls2}

con = ([con1, con2, con3, con4])

scipy.optimize.minimize(fitness2, opt, method = 'trust-constr', jac = 
'cs', hess = h1, constraints = con)

Any idea of how to solve it?

dallonsi
  • 1,299
  • 1
  • 8
  • 29

1 Answers1

1

According to the Scipy documentation, your variable con must be a dictionary. There is also an example, con must be something like:

cons = ({'type': 'ineq', 'fun': lambda x:  x[0] - 2 * x[1] + 2},
        {'type': 'ineq', 'fun': lambda x: -x[0] - 2 * x[1] + 6},
        {'type': 'ineq', 'fun': lambda x: -x[0] + 2 * x[1] + 2})

So in your case, do this:

con = (con1, con2, con3, con4)
dallonsi
  • 1,299
  • 1
  • 8
  • 29
  • still doesn't work even if i do it this way, same message error comes out – luchino_prince Apr 12 '19 at 12:25
  • ok, then, can you udpate your question with a minimal code example that I can reproduce ? – dallonsi Apr 12 '19 at 12:35
  • 1
    I found the problem, for the case of 'trust-constr' you have to create the constraints trough the function LinearConstraint of the same module, for the other options this problem isn't encountered – luchino_prince Apr 12 '19 at 15:53