IpStdCInterface.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /*************************************************************************
  2. Copyright (C) 2004, 2010 International Business Machines and others.
  3. All Rights Reserved.
  4. This code is published under the Eclipse Public License.
  5. $Id: IpStdCInterface.h 2082 2012-02-16 03:00:34Z andreasw $
  6. Authors: Carl Laird, Andreas Waechter IBM 2004-09-02
  7. *************************************************************************/
  8. #ifndef __IPSTDCINTERFACE_H__
  9. #define __IPSTDCINTERFACE_H__
  10. #ifndef IPOPT_EXPORT
  11. #ifdef _MSC_VER
  12. #ifdef IPOPT_DLL
  13. #define IPOPT_EXPORT(type) __declspec(dllexport) type __cdecl
  14. #else
  15. #define IPOPT_EXPORT(type) type __cdecl
  16. #endif
  17. #else
  18. #define IPOPT_EXPORT(type) type
  19. #endif
  20. #endif
  21. #ifdef __cplusplus
  22. extern "C"
  23. {
  24. #endif
  25. /** Type for all number. We need to make sure that this is
  26. identical with what is defined in Common/IpTypes.hpp */
  27. typedef double Number;
  28. /** Type for all incides. We need to make sure that this is
  29. identical with what is defined in Common/IpTypes.hpp */
  30. typedef int Index;
  31. /** Type for all integers. We need to make sure that this is
  32. identical with what is defined in Common/IpTypes.hpp */
  33. typedef int Int;
  34. /* This includes the SolverReturn enum type */
  35. #include "IpReturnCodes.h"
  36. /** Structure collecting all information about the problem
  37. * definition and solve statistics etc. This is defined in the
  38. * source file. */
  39. struct IpoptProblemInfo;
  40. /** Pointer to a Ipopt Problem. */
  41. typedef struct IpoptProblemInfo* IpoptProblem;
  42. /** define a boolean type for C */
  43. typedef int Bool;
  44. #ifndef TRUE
  45. # define TRUE (1)
  46. #endif
  47. #ifndef FALSE
  48. # define FALSE (0)
  49. #endif
  50. /** A pointer for anything that is to be passed between the called
  51. * and individual callback function */
  52. typedef void * UserDataPtr;
  53. /** Type defining the callback function for evaluating the value of
  54. * the objective function. Return value should be set to false if
  55. * there was a problem doing the evaluation. */
  56. typedef Bool (*Eval_F_CB)(Index n, Number* x, Bool new_x,
  57. Number* obj_value, UserDataPtr user_data);
  58. /** Type defining the callback function for evaluating the gradient of
  59. * the objective function. Return value should be set to false if
  60. * there was a problem doing the evaluation. */
  61. typedef Bool (*Eval_Grad_F_CB)(Index n, Number* x, Bool new_x,
  62. Number* grad_f, UserDataPtr user_data);
  63. /** Type defining the callback function for evaluating the value of
  64. * the constraint functions. Return value should be set to false if
  65. * there was a problem doing the evaluation. */
  66. typedef Bool (*Eval_G_CB)(Index n, Number* x, Bool new_x,
  67. Index m, Number* g, UserDataPtr user_data);
  68. /** Type defining the callback function for evaluating the Jacobian of
  69. * the constrant functions. Return value should be set to false if
  70. * there was a problem doing the evaluation. */
  71. typedef Bool (*Eval_Jac_G_CB)(Index n, Number *x, Bool new_x,
  72. Index m, Index nele_jac,
  73. Index *iRow, Index *jCol, Number *values,
  74. UserDataPtr user_data);
  75. /** Type defining the callback function for evaluating the Hessian of
  76. * the Lagrangian function. Return value should be set to false if
  77. * there was a problem doing the evaluation. */
  78. typedef Bool (*Eval_H_CB)(Index n, Number *x, Bool new_x, Number obj_factor,
  79. Index m, Number *lambda, Bool new_lambda,
  80. Index nele_hess, Index *iRow, Index *jCol,
  81. Number *values, UserDataPtr user_data);
  82. /** Type defining the callback function for giving intermediate
  83. * execution control to the user. If set, it is called once per
  84. * iteration, providing the user with some information on the state
  85. * of the optimization. This can be used to print some
  86. * user-defined output. It also gives the user a way to terminate
  87. * the optimization prematurely. If this method returns false,
  88. * Ipopt will terminate the optimization. */
  89. typedef Bool (*Intermediate_CB)(Index alg_mod, /* 0 is regular, 1 is resto */
  90. Index iter_count, Number obj_value,
  91. Number inf_pr, Number inf_du,
  92. Number mu, Number d_norm,
  93. Number regularization_size,
  94. Number alpha_du, Number alpha_pr,
  95. Index ls_trials, UserDataPtr user_data);
  96. /** Function for creating a new Ipopt Problem object. This function
  97. * returns an object that can be passed to the IpoptSolve call. It
  98. * contains the basic definition of the optimization problem, such
  99. * as number of variables and constraints, bounds on variables and
  100. * constraints, information about the derivatives, and the callback
  101. * function for the computation of the optimization problem
  102. * functions and derivatives. During this call, the options file
  103. * PARAMS.DAT is read as well.
  104. *
  105. * If NULL is returned, there was a problem with one of the inputs
  106. * or reading the options file. */
  107. IPOPT_EXPORT(IpoptProblem) CreateIpoptProblem(
  108. Index n /** Number of optimization variables */
  109. , Number* x_L /** Lower bounds on variables. This array of
  110. size n is copied internally, so that the
  111. caller can change the incoming data after
  112. return without that IpoptProblem is
  113. modified. Any value less or equal than
  114. the number specified by option
  115. 'nlp_lower_bound_inf' is interpreted to
  116. be minus infinity. */
  117. , Number* x_U /** Upper bounds on variables. This array of
  118. size n is copied internally, so that the
  119. caller can change the incoming data after
  120. return without that IpoptProblem is
  121. modified. Any value greater or equal
  122. than the number specified by option
  123. 'nlp_upper_bound_inf' is interpreted to
  124. be plus infinity. */
  125. , Index m /** Number of constraints. */
  126. , Number* g_L /** Lower bounds on constraints. This array of
  127. size m is copied internally, so that the
  128. caller can change the incoming data after
  129. return without that IpoptProblem is
  130. modified. Any value less or equal than
  131. the number specified by option
  132. 'nlp_lower_bound_inf' is interpreted to
  133. be minus infinity. */
  134. , Number* g_U /** Upper bounds on constraints. This array of
  135. size m is copied internally, so that the
  136. caller can change the incoming data after
  137. return without that IpoptProblem is
  138. modified. Any value greater or equal
  139. than the number specified by option
  140. 'nlp_upper_bound_inf' is interpreted to
  141. be plus infinity. */
  142. , Index nele_jac /** Number of non-zero elements in constraint
  143. Jacobian. */
  144. , Index nele_hess /** Number of non-zero elements in Hessian of
  145. Lagrangian. */
  146. , Index index_style /** indexing style for iRow & jCol,
  147. 0 for C style, 1 for Fortran style */
  148. , Eval_F_CB eval_f /** Callback function for evaluating
  149. objective function */
  150. , Eval_G_CB eval_g /** Callback function for evaluating
  151. constraint functions */
  152. , Eval_Grad_F_CB eval_grad_f
  153. /** Callback function for evaluating gradient
  154. of objective function */
  155. , Eval_Jac_G_CB eval_jac_g
  156. /** Callback function for evaluating Jacobian
  157. of constraint functions */
  158. , Eval_H_CB eval_h /** Callback function for evaluating Hessian
  159. of Lagrangian function */
  160. );
  161. /** Method for freeing a previously created IpoptProblem. After
  162. freeing an IpoptProblem, it cannot be used anymore. */
  163. IPOPT_EXPORT(void) FreeIpoptProblem(IpoptProblem ipopt_problem);
  164. /** Function for adding a string option. Returns FALSE the option
  165. * could not be set (e.g., if keyword is unknown) */
  166. IPOPT_EXPORT(Bool) AddIpoptStrOption(IpoptProblem ipopt_problem, char* keyword, char* val);
  167. /** Function for adding a Number option. Returns FALSE the option
  168. * could not be set (e.g., if keyword is unknown) */
  169. IPOPT_EXPORT(Bool) AddIpoptNumOption(IpoptProblem ipopt_problem, char* keyword, Number val);
  170. /** Function for adding an Int option. Returns FALSE the option
  171. * could not be set (e.g., if keyword is unknown) */
  172. IPOPT_EXPORT(Bool) AddIpoptIntOption(IpoptProblem ipopt_problem, char* keyword, Int val);
  173. /** Function for opening an output file for a given name with given
  174. * printlevel. Returns false, if there was a problem opening the
  175. * file. */
  176. IPOPT_EXPORT(Bool) OpenIpoptOutputFile(IpoptProblem ipopt_problem, char* file_name,
  177. Int print_level);
  178. /** Optional function for setting scaling parameter for the NLP.
  179. * This corresponds to the get_scaling_parameters method in TNLP.
  180. * If the pointers x_scaling or g_scaling are NULL, then no scaling
  181. * for x resp. g is done. */
  182. IPOPT_EXPORT(Bool) SetIpoptProblemScaling(IpoptProblem ipopt_problem,
  183. Number obj_scaling,
  184. Number* x_scaling,
  185. Number* g_scaling);
  186. /** Setting a callback function for the "intermediate callback"
  187. * method in the TNLP. This gives control back to the user once
  188. * per iteration. If set, it provides the user with some
  189. * information on the state of the optimization. This can be used
  190. * to print some user-defined output. It also gives the user a way
  191. * to terminate the optimization prematurely. If the callback
  192. * method returns false, Ipopt will terminate the optimization.
  193. * Calling this set method to set the CB pointer to NULL disables
  194. * the intermediate callback functionality. */
  195. IPOPT_EXPORT(Bool) SetIntermediateCallback(IpoptProblem ipopt_problem,
  196. Intermediate_CB intermediate_cb);
  197. /** Function calling the Ipopt optimization algorithm for a problem
  198. previously defined with CreateIpoptProblem. The return
  199. specified outcome of the optimization procedure (e.g., success,
  200. failure etc).
  201. */
  202. IPOPT_EXPORT(enum ApplicationReturnStatus) IpoptSolve(
  203. IpoptProblem ipopt_problem
  204. /** Problem that is to be optimized. Ipopt
  205. will use the options previously specified with
  206. AddIpoptOption (etc) for this problem. */
  207. , Number* x /** Input: Starting point
  208. Output: Optimal solution */
  209. , Number* g /** Values of constraint at final point
  210. (output only - ignored if set to NULL) */
  211. , Number* obj_val /** Final value of objective function
  212. (output only - ignored if set to NULL) */
  213. , Number* mult_g /** Input: Initial values for the constraint
  214. multipliers (only if warm start option
  215. is chosen)
  216. Output: Final multipliers for constraints
  217. (ignored if set to NULL) */
  218. , Number* mult_x_L /** Input: Initial values for the multipliers for
  219. lower variable bounds (only if warm start
  220. option is chosen)
  221. Output: Final multipliers for lower variable
  222. bounds (ignored if set to NULL) */
  223. , Number* mult_x_U /** Input: Initial values for the multipliers for
  224. upper variable bounds (only if warm start
  225. option is chosen)
  226. Output: Final multipliers for upper variable
  227. bounds (ignored if set to NULL) */
  228. , UserDataPtr user_data
  229. /** Pointer to user data. This will be
  230. passed unmodified to the callback
  231. functions. */
  232. );
  233. /**
  234. void IpoptStatisticsCounts;
  235. void IpoptStatisticsInfeasibilities; */
  236. #ifdef __cplusplus
  237. } /* extern "C" { */
  238. #endif
  239. #endif