1

I'm trying to understand how shgo has to be used. In the following example, I would expect that no solution can be found, because the constraint function always returns 1.0 even though it's supposed to be equal to zero. However, shgo terminates successfully:

>>> from scipy.optimize import shgo
>>> shgo(func=lambda x: -x.sum(), bounds=[(0, 1)]*5, constraints=({'type':'eq','fun': lambda x: 1.0}))
     fun: -5.0
    funl: array([-5.])
 message: 'Optimization terminated successfully.'
    nfev: 39
     nit: 2
   nlfev: 6
   nlhev: 0
   nljev: 1
 success: True
       x: array([1., 1., 1., 1., 1.])
      xl: array([[1., 1., 1., 1., 1.]])

How are constraint functions meant to be used?

Christopher
  • 2,005
  • 3
  • 24
  • 50

0 Answers0