C# Class Cureos.Numerics.IpoptProblem

Managed wrapper and base class for setup and solution of an Ipopt problem.
Inheritance: IDisposable
显示文件 Open project: cureos/csipopt Class Usage Examples

Public Methods

Method Description
AddOption ( string keyword, double val ) : bool

Function for adding a floating point option.

AddOption ( string keyword, int val ) : bool

Function for adding an integer option.

AddOption ( string keyword, string val ) : bool

Function for adding a string option.

Dispose ( ) : void

Implement the IDisposable interface to release the Ipopt DLL resources held by this class

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 ) : System

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.

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 ) : System

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.

OpenOutputFile ( string file_name, int print_level ) : bool

Method for opening an output file for a given name with given print level.

SetIntermediateCallback ( IntermediateDelegate intermediate_cb ) : bool

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.

SetIntermediateCallback ( Intermediate_CB intermediate_cb ) : bool

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.

SetScaling ( double obj_scaling, double x_scaling, double g_scaling ) : bool

Optional function for setting scaling parameter for the NLP. This corresponds to the get_scaling_parameters method in TNLP. If the pointers x_scaling or g_scaling are null, then no scaling for x resp. g is done.

SolveProblem ( double x, double &obj_val, double g = null, double mult_g = null, double mult_x_L = null, double mult_x_U = null ) : IpoptReturnCode

Function calling the IPOPT optimization algorithm for a problem previously defined with the constructor. IPOPT will use the options previously specified with AddOption for this problem.

eval_f ( int n, double x, bool new_x, double &obj_value ) : bool

Dummy implementation of the managed objective function evaluation delegate. Recommended action is to override this method in a subclass and use the protected constructor of this base class to initialize the subclassed object.

eval_g ( int n, double x, bool new_x, int m, double g ) : bool

Dummy implementation of the managed constraints evaluation delegate. Recommended action is to override this method in a subclass and use the protected constructor of this base class to initialize the subclassed object.

eval_grad_f ( int n, double x, bool new_x, double grad_f ) : bool

Dummy implementation of the managed objective function gradient evaluation delegate. Recommended action is to override this method in a subclass and use the protected constructor of this base class to initialize the subclassed object.

eval_h ( int n, double x, bool new_x, double obj_factor, int m, double lambda, bool new_lambda, int nele_hess, int iRow, int jCol, double values ) : bool

Dummy implementation of the managed Hessian evaluation delegate. Recommended action is to override this method in a subclass and use the protected constructor of this base class to initialize the subclassed object.

eval_jac_g ( int n, double x, bool new_x, int m, int nele_jac, int iRow, int jCol, double values ) : bool

Dummy implementation of the managed Jacobian evaluation delegate. Recommended action is to override this method in a subclass and use the protected constructor of this base class to initialize the subclassed object.

intermediate ( IpoptAlgorithmMode alg_mod, int iter_count, double obj_value, double inf_pr, double inf_du, double mu, double d_norm, double regularization_size, double alpha_du, double alpha_pr, int ls_trials ) : bool

Dummy implementation of the managed intermediate callback method delegate. Recommended action is to override this method in a subclass and use the protected constructor of this base class to initialize the subclassed object.

Protected Methods

Method Description
Dispose ( bool disposing ) : void

Dispose(bool disposing) executes in two distinct scenarios. If disposing equals true, the method has been called directly or indirectly by a user's code. Managed and unmanaged resources can be disposed. If disposing equals false, the method has been called by the runtime from inside the finalizer and you should not reference other objects. Only unmanaged resources can be disposed.

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 ) : System

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.

Private Methods

Method Description
eval_f ( int n, double x, IpoptBoolType new_x, double &obj_value, IntPtr p_user_data ) : IpoptBoolType
eval_g ( int n, double x, IpoptBoolType new_x, int m, double g, IntPtr p_user_data ) : IpoptBoolType
eval_grad_f ( int n, double x, IpoptBoolType new_x, double grad_f, IntPtr p_user_data ) : IpoptBoolType
eval_h ( int n, IntPtr p_x, IpoptBoolType new_x, double obj_factor, int m, IntPtr p_lambda, IpoptBoolType new_lambda, int nele_hess, IntPtr p_iRow, IntPtr p_jCol, IntPtr p_values, IntPtr p_user_data ) : IpoptBoolType
eval_h ( int n, double x, IpoptBoolType new_x, double obj_factor, int m, double lambda, IpoptBoolType new_lambda, int nele_hess, int iRow, int jCol, double values, IntPtr p_user_data ) : IpoptBoolType
eval_jac_g ( int n, IntPtr p_x, IpoptBoolType new_x, int m, int nele_jac, IntPtr p_iRow, IntPtr p_jCol, IntPtr p_values, IntPtr p_user_data ) : IpoptBoolType
eval_jac_g ( int n, double x, IpoptBoolType new_x, int m, int nele_jac, int iRow, int jCol, double values, IntPtr p_user_data ) : IpoptBoolType
intermediate ( IpoptAlgorithmMode alg_mod, int iter_count, double obj_value, double inf_pr, double inf_du, double mu, double d_norm, double regularization_size, double alpha_du, double alpha_pr, int ls_trials, IntPtr p_user_data ) : IpoptBoolType

Method Details

AddOption() public method

Function for adding a floating point option.
public AddOption ( string keyword, double val ) : bool
keyword string Name of option
val double Floating point value of option
return bool

AddOption() public method

Function for adding an integer option.
public AddOption ( string keyword, int val ) : bool
keyword string Name of option
val int Integer value of option
return bool

AddOption() public method

Function for adding a string option.
public AddOption ( string keyword, string val ) : bool
keyword string Name of option
val string String value of option
return bool

Dispose() public method

Implement the IDisposable interface to release the Ipopt DLL resources held by this class
public Dispose ( ) : void
return void

Dispose() protected method

Dispose(bool disposing) executes in two distinct scenarios. If disposing equals true, the method has been called directly or indirectly by a user's code. Managed and unmanaged resources can be disposed. If disposing equals false, the method has been called by the runtime from inside the finalizer and you should not reference other objects. Only unmanaged resources can be disposed.
protected Dispose ( bool disposing ) : void
disposing bool true if Dispose method is explicitly called, false otherwise.
return void

IpoptProblem() public method

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.
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 ) : System
n int Number of optimization variables
x_L double 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.
x_U double 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.
m int Number of constraints.
g_L double 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.
g_U double 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.
nele_jac int Number of non-zero elements in constraint Jacobian.
nele_hess int Number of non-zero elements in Hessian of Lagrangian.
eval_f_cb Eval_F_CB Native callback function for evaluating objective function
eval_g_cb Eval_G_CB Native callback function for evaluating constraint functions
eval_grad_f_cb Eval_Grad_F_CB Native callback function for evaluating gradient of objective function
eval_jac_g_cb Eval_Jac_G_CB Native callback function for evaluating Jacobian of constraint functions
eval_h_cb Eval_H_CB Native callback function for evaluating Hessian of Lagrangian function
return System

IpoptProblem() public method

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.
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 ) : System
n int Number of optimization variables
x_L double 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.
x_U double 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.
m int Number of constraints.
g_L double 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.
g_U double 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.
nele_jac int Number of non-zero elements in constraint Jacobian.
nele_hess int Number of non-zero elements in Hessian of Lagrangian.
eval_f_cb EvaluateObjectiveDelegate Managed callback function for evaluating objective function
eval_g_cb EvaluateConstraintsDelegate Managed callback function for evaluating constraint functions
eval_grad_f_cb EvaluateObjectiveGradientDelegate Managed callback function for evaluating gradient of objective function
eval_jac_g_cb EvaluateJacobianDelegate Managed callback function for evaluating Jacobian of constraint functions
eval_h_cb EvaluateHessianDelegate Managed callback function for evaluating Hessian of Lagrangian function
return System

IpoptProblem() protected method

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.
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 ) : System
n int Number of optimization variables
x_L double 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.
x_U double 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.
m int Number of constraints.
g_L double 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.
g_U double 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.
nele_jac int Number of non-zero elements in constraint Jacobian.
nele_hess int Number of non-zero elements in Hessian of Lagrangian.
useNativeCallbackFunctions bool If set to true, native callback functions are used to setup /// the Ipopt problem; if set to false, managed callback functions are used.
useHessianApproximation bool 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.
useIntermediateCallback bool 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.
return System

OpenOutputFile() public method

Method for opening an output file for a given name with given print level.
public OpenOutputFile ( string file_name, int print_level ) : bool
file_name string Name of output file
print_level int Level of printed information
return bool

SetIntermediateCallback() public method

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.
public SetIntermediateCallback ( IntermediateDelegate intermediate_cb ) : bool
intermediate_cb IntermediateDelegate Managed intermediate callback function
return bool

SetIntermediateCallback() public method

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.
public SetIntermediateCallback ( Intermediate_CB intermediate_cb ) : bool
intermediate_cb Intermediate_CB Native intermediate callback function
return bool

SetScaling() public method

Optional function for setting scaling parameter for the NLP. This corresponds to the get_scaling_parameters method in TNLP. If the pointers x_scaling or g_scaling are null, then no scaling for x resp. g is done.
public SetScaling ( double obj_scaling, double x_scaling, double g_scaling ) : bool
obj_scaling double Scaling of the objective function
x_scaling double Scaling of the problem variables
g_scaling double Scaling of the constraint functions
return bool

SolveProblem() public method

Function calling the IPOPT optimization algorithm for a problem previously defined with the constructor. IPOPT will use the options previously specified with AddOption for this problem.
public SolveProblem ( double x, double &obj_val, double g = null, double mult_g = null, double mult_x_L = null, double mult_x_U = null ) : IpoptReturnCode
x double Input: Starting point; Output: Optimal solution
obj_val double Final value of objective function (output only)
g double Values of constraint at final point (output only - ignored if null on input)
mult_g double Final multipliers for constraints (output only - ignored if null on input)
mult_x_L double Final multipliers for lower variable bounds (output only - ignored if null on input)
mult_x_U double Final multipliers for upper variable bounds (output only - ignored if null on input)
return IpoptReturnCode

eval_f() public method

Dummy implementation of the managed objective function evaluation delegate. Recommended action is to override this method in a subclass and use the protected constructor of this base class to initialize the subclassed object.
public eval_f ( int n, double x, bool new_x, double &obj_value ) : bool
n int
x double
new_x bool
obj_value double
return bool

eval_g() public method

Dummy implementation of the managed constraints evaluation delegate. Recommended action is to override this method in a subclass and use the protected constructor of this base class to initialize the subclassed object.
public eval_g ( int n, double x, bool new_x, int m, double g ) : bool
n int
x double
new_x bool
m int
g double
return bool

eval_grad_f() public method

Dummy implementation of the managed objective function gradient evaluation delegate. Recommended action is to override this method in a subclass and use the protected constructor of this base class to initialize the subclassed object.
public eval_grad_f ( int n, double x, bool new_x, double grad_f ) : bool
n int
x double
new_x bool
grad_f double
return bool

eval_h() public method

Dummy implementation of the managed Hessian evaluation delegate. Recommended action is to override this method in a subclass and use the protected constructor of this base class to initialize the subclassed object.
public eval_h ( int n, double x, bool new_x, double obj_factor, int m, double lambda, bool new_lambda, int nele_hess, int iRow, int jCol, double values ) : bool
n int
x double
new_x bool
obj_factor double
m int
lambda double
new_lambda bool
nele_hess int
iRow int
jCol int
values double
return bool

eval_jac_g() public method

Dummy implementation of the managed Jacobian evaluation delegate. Recommended action is to override this method in a subclass and use the protected constructor of this base class to initialize the subclassed object.
public eval_jac_g ( int n, double x, bool new_x, int m, int nele_jac, int iRow, int jCol, double values ) : bool
n int
x double
new_x bool
m int
nele_jac int
iRow int
jCol int
values double
return bool

intermediate() public method

Dummy implementation of the managed intermediate callback method delegate. Recommended action is to override this method in a subclass and use the protected constructor of this base class to initialize the subclassed object.
public intermediate ( IpoptAlgorithmMode alg_mod, int iter_count, double obj_value, double inf_pr, double inf_du, double mu, double d_norm, double regularization_size, double alpha_du, double alpha_pr, int ls_trials ) : bool
alg_mod IpoptAlgorithmMode
iter_count int
obj_value double
inf_pr double
inf_du double
mu double
d_norm double
regularization_size double
alpha_du double
alpha_pr double
ls_trials int
return bool