private SetIntermediateCallback ( |
||
ipopt_problem | ||
intermediate_cb | Intermediate_CB | |
Résultat | IpoptBoolType |
public void SetIntermediateCallback_CallbackFunctionDefined_CallbackFunctionCalled() { const bool expected = true; IpoptAdapter.SetIntermediateCallback(_instance, _hs037.intermediate); _hs037.hasIntermediateBeenCalled = false; var x = new[] { 10.0, 10.0, 10.0 }; double obj; IpoptAdapter.IpoptSolve(_instance, x, null, out obj, null, null, null, IntPtr.Zero); var actual = _hs037.hasIntermediateBeenCalled; Assert.AreEqual(expected, actual); }
/// <summary> /// Setting a callback function for the "intermediate callback" /// method in the optimizer. This gives control back to the user once /// per iteration. If set, it provides the user with some /// information on the state of the optimization. This can be used /// to print some user-defined output. It also gives the user a way /// to terminate the optimization prematurely. If the callback /// method returns false, Ipopt will terminate the optimization. /// Calling this set method to set the CB pointer to null disables /// the intermediate callback functionality. /// </summary> /// <param name="intermediate_cb">Native intermediate callback function</param> /// <returns>true if the callback function could be set successfully, false otherwise</returns> public bool SetIntermediateCallback(Intermediate_CB intermediate_cb) { return(IsInitialized && IpoptAdapter.SetIntermediateCallback(m_problem, m_intermediate_cb = intermediate_cb) == IpoptBoolType.True); }
/// <summary> /// Setting a callback function for the "intermediate callback" /// method in the optimizer. This gives control back to the user once /// per iteration. If set, it provides the user with some /// information on the state of the optimization. This can be used /// to print some user-defined output. It also gives the user a way /// to terminate the optimization prematurely. If the callback /// method returns false, Ipopt will terminate the optimization. /// Calling this set method to set the CB pointer to null disables /// the intermediate callback functionality. /// </summary> /// <param name="intermediate_cb">Managed intermediate callback function</param> /// <returns>true if the callback function could be set successfully, false otherwise</returns> public bool SetIntermediateCallback(IntermediateDelegate intermediate_cb) { return(IsInitialized && IpoptAdapter.SetIntermediateCallback( m_problem, m_intermediate_cb = new IntermediateReporter(intermediate_cb).Report) == IpoptBoolType.True); }