private CreateIpoptProblem ( int n, double x_L, double x_U, int m, double g_L, double g_U, int nele_jac, int nele_hess, IpoptIndexStyle index_style, Eval_F_CB eval_f, Eval_G_CB eval_g, Eval_Grad_F_CB eval_grad_f, Eval_Jac_G_CB eval_jac_g, Eval_H_CB eval_h ) : |
||
n | int | |
x_L | double | |
x_U | double | |
m | int | |
g_L | double | |
g_U | double | |
nele_jac | int | |
nele_hess | int | |
index_style | IpoptIndexStyle | |
eval_f | Eval_F_CB | |
eval_g | Eval_G_CB | |
eval_grad_f | Eval_Grad_F_CB | |
eval_jac_g | Eval_Jac_G_CB | |
eval_h | Eval_H_CB | |
Résultat |
public void Setup() { _hs037 = new HS037(); _instance = IpoptAdapter.CreateIpoptProblem(_hs037._n, _hs037._x_L, _hs037._x_U, _hs037._m, _hs037._g_L, _hs037._g_U, _hs037._nele_jac, _hs037._nele_hess, IpoptIndexStyle.C, _hs037.eval_f, _hs037.eval_g, _hs037.eval_grad_f, _hs037.eval_jac_g, _hs037.eval_h); IpoptAdapter.AddIpoptStrOption(_instance, "hessian_approximation", "limited-memory"); IpoptAdapter.AddIpoptIntOption(_instance, "limited_memory_max_history", 5); }
/// <summary> /// Constructor for creating a new Ipopt Problem object using native /// 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">Native callback function for evaluating objective function</param> /// <param name="eval_g_cb">Native callback function for evaluating constraint functions</param> /// <param name="eval_grad_f_cb">Native callback function for evaluating gradient of objective function</param> /// <param name="eval_jac_g_cb">Native callback function for evaluating Jacobian of constraint functions</param> /// <param name="eval_h_cb">Native 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, Eval_F_CB eval_f_cb, Eval_G_CB eval_g_cb, Eval_Grad_F_CB eval_grad_f_cb, Eval_Jac_G_CB eval_jac_g_cb, Eval_H_CB eval_h_cb) { m_eval_f_cb = eval_f_cb; m_eval_g_cb = eval_g_cb; m_eval_grad_f_cb = eval_grad_f_cb; m_eval_jac_g_cb = eval_jac_g_cb; m_eval_h_cb = eval_h_cb; 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; }
/// <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; }
/// <summary> /// Constructor for creating a subclassed Ipopt Problem object using managed or /// native function delegates. This is the preferred constructor when /// subclassing IpoptProblem. Prerequisite is that the managed/native optimization /// function delegates are implemented in the inheriting class. /// 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="useNativeCallbackFunctions">If set to true, native callback functions are used to setup /// the Ipopt problem; if set to false, managed callback functions are used.</param> /// <param name="useHessianApproximation">If set to true, the Ipopt optimizer creates a limited memory /// Hessian approximation and the eval_h (managed or native) method need not be implemented. /// If set to false, an exact Hessian should be evaluated using the appropriate Hessian evaluation method.</param> /// <param name="useIntermediateCallback">If set to true, the intermediate method (managed or native) will be called /// after each full iteration. If false, the intermediate callback function will not be called.</param> protected IpoptProblem(int n, double[] x_L, double[] x_U, int m, double[] g_L, double[] g_U, int nele_jac, int nele_hess, bool useNativeCallbackFunctions = false, bool useHessianApproximation = false, bool useIntermediateCallback = false) { if (useNativeCallbackFunctions) { m_eval_f_cb = eval_f; m_eval_g_cb = eval_g; m_eval_grad_f_cb = eval_grad_f; m_eval_jac_g_cb = eval_jac_g; m_eval_h_cb = eval_h; } else { m_eval_f_cb = new ObjectiveEvaluator(eval_f).Evaluate; m_eval_g_cb = new ConstraintsEvaluator(eval_g).Evaluate; m_eval_grad_f_cb = new ObjectiveGradientEvaluator(eval_grad_f).Evaluate; m_eval_jac_g_cb = new JacobianEvaluator(eval_jac_g).Evaluate; m_eval_h_cb = new HessianEvaluator(eval_h).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); if (useHessianApproximation) { AddOption("hessian_approximation", "limited-memory"); } if (useIntermediateCallback) { if (useNativeCallbackFunctions) { SetIntermediateCallback((Intermediate_CB)intermediate); } else { SetIntermediateCallback((IntermediateDelegate)intermediate); } } m_disposed = false; }