/// <summary> /// Constructor for creating a new Ipopt Problem object. This function /// returns an object that can be passed to the IpoptSolve call. It /// contains the basic definition of the optimization problem, such /// as number of variables and constraints, bounds on variables and /// constraints, information about the derivatives, and the callback /// function for the computation of the optimization problem /// functions and derivatives. During this call, the options file /// PARAMS.DAT is read as well. /// </summary> /// <param name="n">Number of optimization variables</param> /// <param name="x_L">Lower bounds on variables. This array of size n is copied internally, so that the /// caller can change the incoming data after return without that IpoptProblem is modified. Any value /// less or equal than the number specified by option 'nlp_lower_bound_inf' is interpreted to be minus infinity.</param> /// <param name="x_U">Upper bounds on variables. This array of size n is copied internally, so that the /// caller can change the incoming data after return without that IpoptProblem is modified. Any value /// greater or equal than the number specified by option 'nlp_upper_bound_inf' is interpreted to be plus infinity.</param> /// <param name="m">Number of constraints.</param> /// <param name="g_L">Lower bounds on constraints. This array of size m is copied internally, so that the /// caller can change the incoming data after return without that IpoptProblem is modified. Any value /// less or equal than the number specified by option 'nlp_lower_bound_inf' is interpreted to be minus infinity.</param> /// <param name="g_U">Upper bounds on constraints. This array of size m is copied internally, so that the /// caller can change the incoming data after return without that IpoptProblem is modified. Any value /// greater or equal than the number specified by option 'nlp_upper_bound_inf' is interpreted to be plus infinity.</param> /// <param name="nele_jac">Number of non-zero elements in constraint Jacobian.</param> /// <param name="nele_hess">Number of non-zero elements in Hessian of Lagrangian.</param> /// <param name="eval_f">Callback function for evaluating objective function</param> /// <param name="eval_g">Callback function for evaluating constraint functions</param> /// <param name="eval_grad_f">Callback function for evaluating gradient of objective function</param> /// <param name="eval_jac_g">Callback function for evaluating Jacobian of constraint functions</param> /// <param name="eval_h">Callback function for evaluating Hessian of Lagrangian function</param> public Ipopt(int n, double[] x_L, double[] x_U, int m, double[] g_L, double[] g_U, int nele_jac, int nele_hess, EvaluateObjectiveDelegate eval_f, EvaluateConstraintsDelegate eval_g, EvaluateObjectiveGradientDelegate eval_grad_f, EvaluateJacobianDelegate eval_jac_g, EvaluateHessianDelegate eval_h) { unsafe { fixed(double *p_x_L = x_L, p_x_U = x_U, p_g_L = g_L, p_g_U = g_U) { m_eval_f = new ObjectiveEvaluator(eval_f).Evaluate; m_eval_g = new ConstraintsEvaluator(eval_g).Evaluate; m_eval_grad_f = new ObjectiveGradientEvaluator(eval_grad_f).Evaluate; m_eval_jac_g = new JacobianEvaluator(eval_jac_g).Evaluate; m_eval_h = new HessianEvaluator(eval_h).Evaluate; m_intermediate = null; m_problem = CreateIpoptProblem(n, p_x_L, p_x_U, m, p_g_L, p_g_U, nele_jac, nele_hess, 0, m_eval_f, m_eval_g, m_eval_grad_f, m_eval_jac_g, m_eval_h); if (m_problem == IntPtr.Zero) { throw new ArgumentException("Failed to initialize IPOPT problem"); } } } m_disposed = false; }
/// <summary> /// Constructor for creating a new Ipopt Problem object using managed /// function delegates. This function /// initializes an object that can be passed to the IpoptSolve call. It /// contains the basic definition of the optimization problem, such /// as number of variables and constraints, bounds on variables and /// constraints, information about the derivatives, and the callback /// function for the computation of the optimization problem /// functions and derivatives. During this call, the options file /// ipopt.opt is read as well. /// </summary> /// <param name="n">Number of optimization variables</param> /// <param name="x_L">Lower bounds on variables. This array of size n is copied internally, so that the /// caller can change the incoming data after return without that IpoptProblem is modified. Any value /// less or equal than the number specified by option 'nlp_lower_bound_inf' is interpreted to be minus infinity.</param> /// <param name="x_U">Upper bounds on variables. This array of size n is copied internally, so that the /// caller can change the incoming data after return without that IpoptProblem is modified. Any value /// greater or equal than the number specified by option 'nlp_upper_bound_inf' is interpreted to be plus infinity.</param> /// <param name="m">Number of constraints.</param> /// <param name="g_L">Lower bounds on constraints. This array of size m is copied internally, so that the /// caller can change the incoming data after return without that IpoptProblem is modified. Any value /// less or equal than the number specified by option 'nlp_lower_bound_inf' is interpreted to be minus infinity.</param> /// <param name="g_U">Upper bounds on constraints. This array of size m is copied internally, so that the /// caller can change the incoming data after return without that IpoptProblem is modified. Any value /// greater or equal than the number specified by option 'nlp_upper_bound_inf' is interpreted to be plus infinity.</param> /// <param name="nele_jac">Number of non-zero elements in constraint Jacobian.</param> /// <param name="nele_hess">Number of non-zero elements in Hessian of Lagrangian.</param> /// <param name="eval_f_cb">Managed callback function for evaluating objective function</param> /// <param name="eval_g_cb">Managed callback function for evaluating constraint functions</param> /// <param name="eval_grad_f_cb">Managed callback function for evaluating gradient of objective function</param> /// <param name="eval_jac_g_cb">Managed callback function for evaluating Jacobian of constraint functions</param> /// <param name="eval_h_cb">Managed callback function for evaluating Hessian of Lagrangian function</param> public IpoptProblem(int n, double[] x_L, double[] x_U, int m, double[] g_L, double[] g_U, int nele_jac, int nele_hess, EvaluateObjectiveDelegate eval_f_cb, EvaluateConstraintsDelegate eval_g_cb, EvaluateObjectiveGradientDelegate eval_grad_f_cb, EvaluateJacobianDelegate eval_jac_g_cb, EvaluateHessianDelegate eval_h_cb) { m_eval_f_cb = new ObjectiveEvaluator(eval_f_cb).Evaluate; m_eval_g_cb = new ConstraintsEvaluator(eval_g_cb).Evaluate; m_eval_grad_f_cb = new ObjectiveGradientEvaluator(eval_grad_f_cb).Evaluate; m_eval_jac_g_cb = new JacobianEvaluator(eval_jac_g_cb).Evaluate; m_eval_h_cb = new HessianEvaluator(eval_h_cb).Evaluate; m_intermediate_cb = null; m_problem = IpoptAdapter.CreateIpoptProblem(n, x_L, x_U, m, g_L, g_U, nele_jac, nele_hess, IpoptIndexStyle.C, m_eval_f_cb, m_eval_g_cb, m_eval_grad_f_cb, m_eval_jac_g_cb, m_eval_h_cb); m_disposed = false; }
internal HessianEvaluator(EvaluateHessianDelegate eval_h_cb) { m_eval_h_cb = eval_h_cb; }
internal HessianEvaluator(EvaluateHessianDelegate eval_h) { m_eval_h = eval_h; }