File: nlp2.h

package info (click to toggle)
libamplsolver 0~20190702-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid, trixie
  • size: 3,156 kB
  • sloc: ansic: 40,471; asm: 76; sh: 72; fortran: 51; makefile: 16
file content (340 lines) | stat: -rw-r--r-- 7,126 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
/*******************************************************************
Copyright (C) 2017 AMPL Optimization, Inc.; written by David M. Gay.

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that the copyright notice and this permission notice and warranty
disclaimer appear in supporting documentation.

The author and AMPL Optimization, Inc. disclaim all warranties with
regard to this software, including all implied warranties of
merchantability and fitness.  In no event shall the author be liable
for any special, indirect or consequential damages or any damages
whatsoever resulting from loss of use, data or profits, whether in an
action of contract, negligence or other tortious action, arising out
of or in connection with the use or performance of this software.
*******************************************************************/

/* Variant of nlp.h for Hessian times vector computations. */

#ifndef NLP_H2_included
#define NLP_H2_included

#ifndef ASL_included
#include "asl.h"
#endif

#ifdef __cplusplus
 extern "C" {
#endif

typedef struct argpair2 argpair2;
typedef struct cde2 cde2;
typedef struct cexp2 cexp2;
typedef struct cexp21 cexp21;
typedef struct de2 de2;
typedef union  ei2 ei2;
typedef struct expr2 expr2;
typedef struct expr2_f expr2_f;
typedef struct expr2_h expr2_h;
typedef struct expr2_if expr2_if;
typedef struct expr2_v expr2_v;
typedef struct expr2_va expr2_va;
typedef struct funnel2 funnel2;
typedef struct hes_fun hes_fun;
typedef struct list2 list2;
typedef union  uir uir;

typedef real  efunc2 ANSI((expr2* A_ASL));
typedef char *sfunc  ANSI((expr2* A_ASL));

 union
uir {
	int	i;
	real	r;
	};

 union
ei2 {
	expr2	*e;
	expr2	**ep;
	expr2_if*eif;
	expr_n	*en;
	expr2_v	*ev;
	int	i;
	plterm	*p;
	de2	*d;
	real	*rp;
	derp	*D;
	cexp2	*ce;
	};

 struct
expr2 {
	efunc2 *op;
	int a;		/* adjoint index (for gradient computation) */
	expr2 *fwd, *bak;
	uir  dO;	/* deriv of op w.r.t. t in x + t*p */
	real aO;	/* adjoint (in Hv computation) of op */
	real adO;	/* adjoint (in Hv computation) of dO */
	real dL;	/* deriv of op w.r.t. left operand */
	ei2 L, R;	/* left and right operands */
	real dR;	/* deriv of op w.r.t. right operand */
	real dL2;	/* second partial w.r.t. L, L */
	real dLR;	/* second partial w.r.t. L, R */
	real dR2;	/* second partial w.r.t. R, R */
	};

 struct
expr2_v {
	efunc2 *op;
	int a;
	expr2 *fwd, *bak;
	uir dO;
	real aO, adO;
	real v;
	};

 struct
expr2_if {
	efunc2 *op;
	int a;
	expr2 *fwd, *bak;
	uir  dO;
	real aO, adO;
	expr2 *val, *vale, *valf, *e, *T, *Te, *Tf, *F, *Fe, *Ff;
	derp *D, *dT, *dF, *d0;
	ei2 Tv, Fv;
	expr2_if *next, *next2;
	derp *dTlast;
	};

 struct
expr2_va {
	efunc2 *op;
	int a;
	expr2 *fwd, *bak;
	uir  dO;
	real aO, adO;
	expr2 *val, *vale, *valf;
	ei2 L, R;
	expr2_va *next, *next2;
	derp *d0;
	};

 struct
cde2 {
	expr2	*e, *ee, *ef;
	derp	*d;
	int	zaplen;
	int	com11, n_com1;
	};

 struct
de2 {			/* for varargs */
	expr2 *e, *ee, *ef;
	derp *d;
	ei2 dv;
	derp *dlast;	/* for sputhes setup */
	};

 struct
list2 {
	list2	*next;
	ei2	item;
	};

 struct
cexp21 {
	expr2	*e, *ee, *ef;
	linpart	*L;
	int	nlin;
	};

 struct
cexp2 {
	expr2	*e, *ee, *ef;
	linpart	*L;
	int	nlin;
	int	zlen;
	struct linarg2 *la;	/* corresponding to L */
	funnel2	*funneled;
	list2	*cref;
	ei2	z;
	derp	*d;
	int	*vref;
	hes_fun	*hfun;
	};

 struct
funnel2 {
	funnel2	*next;
	cexp2	*ce;
	cde2	fcde;
	derp	*fulld;
	cplist	*cl;
	};

 struct
argpair2 {
	expr2	*e;
	union {
		char	**s;
		real	*v;
		} u;
	};

 struct
expr2_f {
	efunc2 *op;
	int	a;
	expr2 *fwd, *bak;
	uir  dO;
	real aO, adO;
	func_info *fi;
	arglist *al;
	argpair2 *ap, *ape, *sap, *sape;
	argpair2 *da;	/* differentiable args -- nonconstant */
	argpair2 *dae;
	real	**fh;		/* Hessian info */
	expr2	*args[1];
	};

 struct
expr2_h {
	efunc2 *op;
	int	a;
	char	sym[1];
	};

 typedef struct
Edag2info {
	cde2	*con2_de_;	/* constraint deriv. and expr. info */
	cde2	*lcon2_de_;	/* logical constraints */
	cde2	*obj2_de_;	/* objective  deriv. and expr. info */
	expr2_v	*var2_e_;	/* variable values (and related items) */

			/* stuff for "defined" variables */
	funnel2	*f2_b_;
	funnel2	*f2_c_;
	funnel2	*f2_o_;
	expr2_v	*var2_ex_,
		*var2_ex1_;
	cexp2	*cexps2_, *cexpsc_, *cexpso_, *cexpse_;
	cexp21	*cexps21_;
	hes_fun	*hesthread;
	char	*c_class;	/* class of each constraint: */
				/* 0 = constant */
				/* 1 = linear */
				/* 2 = quadratic */
				/* 3 = general nonlinear */
	char	*o_class;	/* class of each objective */
	char	*v_class;	/* class of each defined variable */
	int	c_class_max;	/* max of c_class values */
	int	o_class_max;	/* max of o_class values */
				/* The above are only computed if requested */
				/* by the ASL_find_c_class and */
				/* ASL_find_o_class bits of the flags arg */
				/* to pfgh_read() and pfg_read() */
	int	x0kind_init;
	} Edag2info;

 typedef struct
ASL_fgh {
	Edagpars  p;
	Edaginfo  i;
	Edag2info I;
	} ASL_fgh;

 extern efunc2 *r2_ops_ASL[];
 extern void com21eval_ASL ANSI((ASL_fgh*, int, int));
 extern void com2eval_ASL ANSI((ASL_fgh*, int, int));
 extern void fun2set_ASL ANSI((ASL_fgh*, funnel2 *));
#ifdef __cplusplus
	}
#endif

#ifndef SKIP_NL2_DEFINES
extern efunc2 f2_OPVARVAL_ASL;

#define cexpsc		asl->I.cexpsc_
#define cexpse		asl->I.cexpse_
#define cexpso		asl->I.cexpso_
#define cexps1		asl->I.cexps21_
#define cexps		asl->I.cexps2_
#define con_de		asl->I.con2_de_
#define f_b		asl->I.f2_b_
#define f_c		asl->I.f2_c_
#define f_o		asl->I.f2_o_
#define lcon_de		asl->I.lcon2_de_
#define obj_de		asl->I.obj2_de_
#define var_e		asl->I.var2_e_
#define var_ex1		asl->I.var2_ex1_
#define var_ex		asl->I.var2_ex_

#define argpair	argpair2
#define cde	cde2
#define cexp	cexp2
#define cexp1	cexp21
#define de	de2
#define ei	ei2
#define expr	expr2
#define expr_f	expr2_f
#define expr_h	expr2_h
#define expr_if	expr2_if
#define expr_v	expr2_v
#define expr_va	expr2_va
#define funnel	funnel2
#define list	list2

#define com1eval	com21eval_ASL
#define comeval		com2eval_ASL
#define funnelset	fun2set_ASL
#undef  r_ops
#define r_ops		r2_ops_ASL

#ifndef PSHVREAD
#define f_OPIFSYM	f2_IFSYM_ASL
#define f_OPPLTERM	f2_PLTERM_ASL
#define f_OPFUNCALL	f2_FUNCALL_ASL
#define f_OP1POW	f2_1POW_ASL
#define f_OP2POW	f2_2POW_ASL
#define f_OPCPOW	f2_CPOW_ASL
#define f_OPPLUS	f2_PLUS_ASL
#define f_OPSUMLIST	f2_SUMLIST_ASL
#define f_OPHOL		f2_HOL_ASL
#define f_OPPOW		f2_POW_ASL
#define f_OPVARVAL	f2_VARVAL_ASL
#endif

/* operation classes (for H*v computation) */

enum { /* operation classes (for H*v computation) */
	Hv_binaryR	= 0,
	Hv_binaryLR	= 1,
	Hv_unary	= 2,
	Hv_vararg	= 3,
	Hv_if		= 4,
	Hv_plterm	= 5,
	Hv_sumlist	= 6,
	Hv_func		= 7,
	Hv_negate	= 8,
	Hv_plusR	= 9,
	Hv_plusL	= 10,
	Hv_plusLR	= 11,
	Hv_minusR	= 12,
	Hv_minusLR	= 13,
	Hv_timesR	= 14,
	Hv_timesL	= 15,
	Hv_timesLR	= 16,
	Hv_divLR	= 17
	};

/* treat if as vararg, minusL as plusL, binaryL as unary */

#endif /* SKIP_NL2_DEFINES */

#undef f_OPNUM
#define f_OPNUM (efunc2*)f_OPNUM_ASL
#endif /* NLP_H2_included */