Skip to content

Commit d60808d

Browse files
committed
Scipy: passed constraints list to the minimizer function
1 parent feff9a3 commit d60808d

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

math/scipy/src/ScipyMinimizer.cxx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,9 @@ bool ScipyMinimizer::Minimize()
260260
// minimize(fun, x0, args=(), method=None, jac=None, hess=None, hessp=None, bounds=None, constraints=(), tol=None,
261261
// callback=None, options=None)
262262
PyObject *args = Py_BuildValue("(OO)", fTarget, x0);
263-
PyObject *kw = Py_BuildValue("{s:s,s:O,,s:O,s:O,s:d,s:O}", "method", method.c_str(), "jac", fJacobian, "hess",
264-
fHessian, "bounds", pybounds, "tol", Tolerance(), "options", pyoptions);
263+
PyObject *kw = Py_BuildValue("{s:s,s:O,,s:O,s:O,s:O,s:d,s:O}", "method", method.c_str(), "jac", fJacobian, "hess",
264+
fHessian, "bounds", pybounds,"constraints",fConstraintsList, "tol", Tolerance(),
265+
"options", pyoptions);
265266

266267
PyObject *result = PyObject_Call(fMinimize, args, kw);
267268
if (result == NULL) {
@@ -275,6 +276,8 @@ bool ScipyMinimizer::Minimize()
275276
Py_DECREF(args);
276277
Py_DECREF(kw);
277278
Py_DECREF(x0);
279+
Py_DECREF(fConstraintsList);
280+
fConstraintsList = PyList_New(0);
278281

279282
// if the minimization works
280283
PyObject *pstatus = PyObject_GetAttrString(result, "status");
@@ -401,5 +404,8 @@ void ScipyMinimizer::AddConstraintFunction(std::function<double(const std::vecto
401404
PyDict_SetItemString(pyconst, "type", PyUnicode_FromString(type.c_str()));
402405
PyDict_SetItemString(pyconst, "fun", pyconstfun);
403406
PyList_Append(fConstraintsList, pyconst);
407+
408+
Py_DECREF(ConstError);
409+
Py_DECREF(module);
404410
PyPrint(fConstraintsList);
405411
}

0 commit comments

Comments
 (0)