nlp2.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. /****************************************************************
  2. Copyright (C) 1997-1998, 2000-2001 Lucent Technologies
  3. All Rights Reserved
  4. Permission to use, copy, modify, and distribute this software and
  5. its documentation for any purpose and without fee is hereby
  6. granted, provided that the above copyright notice appear in all
  7. copies and that both that the copyright notice and this
  8. permission notice and warranty disclaimer appear in supporting
  9. documentation, and that the name of Lucent or any of its entities
  10. not be used in advertising or publicity pertaining to
  11. distribution of the software without specific, written prior
  12. permission.
  13. LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  14. INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
  15. IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
  16. SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  17. WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
  18. IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  19. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
  20. THIS SOFTWARE.
  21. ****************************************************************/
  22. /* Variant of nlp.h for Hessian times vector computations. */
  23. #ifndef NLP_H2_included
  24. #define NLP_H2_included
  25. #ifndef ASL_included
  26. #include "asl.h"
  27. #endif
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. typedef struct argpair2 argpair2;
  32. typedef struct cde2 cde2;
  33. typedef struct cexp2 cexp2;
  34. typedef struct cexp21 cexp21;
  35. typedef struct de2 de2;
  36. typedef union ei2 ei2;
  37. typedef struct expr2 expr2;
  38. typedef struct expr2_f expr2_f;
  39. typedef struct expr2_h expr2_h;
  40. typedef struct expr2_if expr2_if;
  41. typedef struct expr2_v expr2_v;
  42. typedef struct expr2_va expr2_va;
  43. typedef struct funnel2 funnel2;
  44. typedef struct hes_fun hes_fun;
  45. typedef struct list2 list2;
  46. typedef union uir uir;
  47. typedef real efunc2 ANSI((expr2* A_ASL));
  48. typedef char *sfunc ANSI((expr2* A_ASL));
  49. union
  50. uir {
  51. int i;
  52. real r;
  53. };
  54. union
  55. ei2 {
  56. expr2 *e;
  57. expr2 **ep;
  58. expr2_if*eif;
  59. expr_n *en;
  60. expr2_v *ev;
  61. int i;
  62. plterm *p;
  63. de2 *d;
  64. real *rp;
  65. derp *D;
  66. cexp2 *ce;
  67. };
  68. struct
  69. expr2 {
  70. efunc2 *op;
  71. int a; /* adjoint index (for gradient computation) */
  72. expr2 *fwd, *bak;
  73. uir dO; /* deriv of op w.r.t. t in x + t*p */
  74. real aO; /* adjoint (in Hv computation) of op */
  75. real adO; /* adjoint (in Hv computation) of dO */
  76. real dL; /* deriv of op w.r.t. left operand */
  77. ei2 L, R; /* left and right operands */
  78. real dR; /* deriv of op w.r.t. right operand */
  79. real dL2; /* second partial w.r.t. L, L */
  80. real dLR; /* second partial w.r.t. L, R */
  81. real dR2; /* second partial w.r.t. R, R */
  82. };
  83. struct
  84. expr2_v {
  85. efunc2 *op;
  86. int a;
  87. expr2 *fwd, *bak;
  88. uir dO;
  89. real aO, adO;
  90. real v;
  91. };
  92. struct
  93. expr2_if {
  94. efunc2 *op;
  95. int a;
  96. expr2 *fwd, *bak;
  97. uir dO;
  98. real aO, adO;
  99. expr2 *val, *vale, *valf, *e, *T, *Te, *Tf, *F, *Fe, *Ff;
  100. derp *D, *dT, *dF, *d0;
  101. ei2 Tv, Fv;
  102. expr2_if *next, *next2;
  103. derp *dTlast;
  104. };
  105. struct
  106. expr2_va {
  107. efunc2 *op;
  108. int a;
  109. expr2 *fwd, *bak;
  110. uir dO;
  111. real aO, adO;
  112. expr2 *val, *vale, *valf;
  113. ei2 L, R;
  114. expr2_va *next, *next2;
  115. derp *d0;
  116. };
  117. struct
  118. cde2 {
  119. expr2 *e, *ee, *ef;
  120. derp *d;
  121. int zaplen;
  122. int com11, n_com1;
  123. };
  124. struct
  125. de2 { /* for varargs */
  126. expr2 *e, *ee, *ef;
  127. derp *d;
  128. ei2 dv;
  129. derp *dlast; /* for sputhes setup */
  130. };
  131. struct
  132. list2 {
  133. list2 *next;
  134. ei2 item;
  135. };
  136. struct
  137. cexp21 {
  138. expr2 *e, *ee, *ef;
  139. linpart *L;
  140. int nlin;
  141. };
  142. struct
  143. cexp2 {
  144. expr2 *e, *ee, *ef;
  145. linpart *L;
  146. int nlin;
  147. funnel2 *funneled;
  148. list2 *cref;
  149. ei2 z;
  150. int zlen;
  151. derp *d;
  152. int *vref;
  153. hes_fun *hfun;
  154. };
  155. struct
  156. funnel2 {
  157. funnel2 *next;
  158. cexp2 *ce;
  159. cde2 fcde;
  160. derp *fulld;
  161. cplist *cl;
  162. };
  163. struct
  164. argpair2 {
  165. expr2 *e;
  166. union {
  167. char **s;
  168. real *v;
  169. } u;
  170. };
  171. struct
  172. expr2_f {
  173. efunc2 *op;
  174. int a;
  175. expr2 *fwd, *bak;
  176. uir dO;
  177. real aO, adO;
  178. func_info *fi;
  179. arglist *al;
  180. argpair2 *ap, *ape, *sap, *sape;
  181. argpair2 *da; /* differentiable args -- nonconstant */
  182. argpair2 *dae;
  183. real **fh; /* Hessian info */
  184. expr2 *args[1];
  185. };
  186. struct
  187. expr2_h {
  188. efunc2 *op;
  189. int a;
  190. char sym[1];
  191. };
  192. typedef struct
  193. Edag2info {
  194. cde2 *con2_de_; /* constraint deriv. and expr. info */
  195. cde2 *lcon2_de_; /* logical constraints */
  196. cde2 *obj2_de_; /* objective deriv. and expr. info */
  197. expr2_v *var2_e_; /* variable values (and related items) */
  198. /* stuff for "defined" variables */
  199. funnel2 *f2_b_;
  200. funnel2 *f2_c_;
  201. funnel2 *f2_o_;
  202. expr2_v *var2_ex_,
  203. *var2_ex1_;
  204. cexp2 *cexps2_, *cexpsc_, *cexpso_, *cexpse_;
  205. cexp21 *cexps21_;
  206. hes_fun *hesthread;
  207. char *c_class; /* class of each constraint: */
  208. /* 0 = constant */
  209. /* 1 = linear */
  210. /* 2 = quadratic */
  211. /* 3 = general nonlinear */
  212. char *o_class; /* class of each objective */
  213. char *v_class; /* class of each defined variable */
  214. int c_class_max; /* max of c_class values */
  215. int o_class_max; /* max of o_class values */
  216. /* The above are only computed if requested */
  217. /* by the ASL_find_c_class and */
  218. /* ASL_find_o_class bits of the flags arg */
  219. /* to pfgh_read() and pfg_read() */
  220. int x0kind_init;
  221. } Edag2info;
  222. typedef struct
  223. ASL_fgh {
  224. Edagpars p;
  225. Edaginfo i;
  226. Edag2info I;
  227. } ASL_fgh;
  228. extern efunc2 *r2_ops_ASL[];
  229. extern void com21eval_ASL ANSI((ASL_fgh*, int, int));
  230. extern void com2eval_ASL ANSI((ASL_fgh*, int, int));
  231. extern void fun2set_ASL ANSI((ASL_fgh*, funnel2 *));
  232. #ifdef __cplusplus
  233. }
  234. #endif
  235. #ifndef SKIP_NL2_DEFINES
  236. extern efunc2 f2_OPVARVAL_ASL;
  237. #define cexpsc asl->I.cexpsc_
  238. #define cexpse asl->I.cexpse_
  239. #define cexpso asl->I.cexpso_
  240. #define cexps1 asl->I.cexps21_
  241. #define cexps asl->I.cexps2_
  242. #define con_de asl->I.con2_de_
  243. #define f_b asl->I.f2_b_
  244. #define f_c asl->I.f2_c_
  245. #define f_o asl->I.f2_o_
  246. #define lcon_de asl->I.lcon2_de_
  247. #define obj_de asl->I.obj2_de_
  248. #define var_e asl->I.var2_e_
  249. #define var_ex1 asl->I.var2_ex1_
  250. #define var_ex asl->I.var2_ex_
  251. #define argpair argpair2
  252. #define cde cde2
  253. #define cexp cexp2
  254. #define cexp1 cexp21
  255. #define de de2
  256. #define ei ei2
  257. #define expr expr2
  258. #define expr_f expr2_f
  259. #define expr_h expr2_h
  260. #define expr_if expr2_if
  261. #define expr_v expr2_v
  262. #define expr_va expr2_va
  263. #define funnel funnel2
  264. #define list list2
  265. #define com1eval com21eval_ASL
  266. #define comeval com2eval_ASL
  267. #define funnelset fun2set_ASL
  268. #undef r_ops
  269. #define r_ops r2_ops_ASL
  270. #ifndef PSHVREAD
  271. #define f_OPIFSYM f2_IFSYM_ASL
  272. #define f_OPPLTERM f2_PLTERM_ASL
  273. #define f_OPFUNCALL f2_FUNCALL_ASL
  274. #define f_OP1POW f2_1POW_ASL
  275. #define f_OP2POW f2_2POW_ASL
  276. #define f_OPCPOW f2_CPOW_ASL
  277. #define f_OPPLUS f2_PLUS_ASL
  278. #define f_OPSUMLIST f2_SUMLIST_ASL
  279. #define f_OPHOL f2_HOL_ASL
  280. #define f_OPPOW f2_POW_ASL
  281. #define f_OPVARVAL f2_VARVAL_ASL
  282. #endif
  283. /* operation classes (for H*v computation) */
  284. #define Hv_binaryR 0
  285. #define Hv_binaryLR 1
  286. #define Hv_unary 2
  287. #define Hv_vararg 3
  288. #define Hv_if 4
  289. #define Hv_plterm 5
  290. #define Hv_sumlist 6
  291. #define Hv_func 7
  292. #define Hv_negate 8
  293. #define Hv_plusR 9
  294. #define Hv_plusL 10
  295. #define Hv_plusLR 11
  296. #define Hv_minusR 12
  297. #define Hv_minusLR 13
  298. #define Hv_timesR 14
  299. #define Hv_timesL 15
  300. #define Hv_timesLR 16
  301. /* treat if as vararg, minusL as plusL, binaryL as unary */
  302. #endif /* SKIP_NL2_DEFINES */
  303. #undef f_OPNUM
  304. #define f_OPNUM (efunc2*)f_OPNUM_ASL
  305. #endif /* NLP_H2_included */