File: duthes.c

package info (click to toggle)
libamplsolver 0~20190702-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,184 kB
  • sloc: ansic: 40,472; asm: 76; sh: 72; fortran: 51; makefile: 16
file content (142 lines) | stat: -rw-r--r-- 3,645 bytes parent folder | download | duplicates (4)
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
/****************************************************************
Copyright (C) 1997, 2001 Lucent Technologies
All Rights Reserved

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, and that the name of Lucent or any of its entities
not be used in advertising or publicity pertaining to
distribution of the software without specific, written prior
permission.

LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES 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.
****************************************************************/

#include "asl_pfgh.h"

 static void
#ifdef KR_headers
add_op(H, og0, t) real *H; ograd *og0; real t;
#else
add_op(real *H, ograd *og0, real t)
#endif
{
	ograd *og, *og1;
	real *Hj, t1;
	int j;

	for(og = og0; og; og = og->next) {
		if ((t1 = t * og->coef)) {
			j = og->varno;
			Hj = H + ((j*(j+1))>>1);
			for(og1 = og0;; og1 = og1->next) {
				Hj[og1->varno] += t1*og1->coef;
				if (og == og1)
					break;
				}
			}
		}
	}

 void
#ifdef KR_headers
duthes_ASL(a, H, nobj, ow, y) ASL *a; real *H; int nobj; real *ow, *y;
#else
duthes_ASL(ASL *a, real *H, int nobj, real *ow, real *y)
#endif
{
	/* dense upper triangle of Hessian */
	int i, j, n, no, noe;
	linarg *la, **lap, **lap1, **lape;
	expr_v *v;
	range *r, *r0;
	real *Hj, *cscale, *owi, *s, *si, t, t1;
	ograd *og, *og1;
	ps_func *p, *pe;
	psg_elem *g, *ge;
	ASL_pfgh *asl;

	asl = pscheck_ASL(a, "duthes");
	xpsg_check_ASL(asl, nobj, ow, y);
	if (nobj >= 0 && nobj < n_obj) {
		no = nobj;
		noe = no + 1;
		owi = ow ? ow + no : &edag_one_ASL;
		}
	else {
		nobj = -1;
		no = noe = 0;
		if ((owi = ow))
			noe = n_obj;
		}

	if (!asl->P.hes_setup_called)
		(*asl->p.Hesset)(a, 1, 0, nlo, 0, nlc);
	s = asl->P.dOscratch;
	n = c_vars >= o_vars ? c_vars : o_vars;
	memset(H, 0, (n*(n+1) >> 1) * sizeof(real));

	r0 = (range*)&asl->P.rlist;
	for(r = asl->P.rlist.next; r != r0; r = r->rlist.next) {
		if ((j = r->n) <= 0)
			continue;
		lap = r->lap;
		lape = lap + j;
		si = s;
		while(lap < lape) {
			*si = 1;
			pshv_prod_ASL(asl, r, nobj, ow, y);
			*si++ = 0;
			la = *lap++;
			for(og = la->nz; og; og = og->next) {
				t = og->coef;
				j = og->varno;
				Hj = H + ((j*(j+1))>>1);
				for(lap1 = r->lap; lap1 < lape; ) {
					la = *lap1++;
					v = la->v;
					if (!(t1 = t * v->aO))
						continue;
					for(og1 = la->nz;
					    og1 && (i = og1->varno) <= j;
					    og1 = og1->next)
						Hj[i] += t1*og1->coef;
					}
				}
			}
		}
	if (asl->P.nobjgroups)
		for(; no < noe; no++)
			if ((t = *owi++)) {
				p = asl->P.ops + no;
				g = p->g;
				for(ge = g + p->ng; g < ge; g++)
					if (g->g2)
						add_op(H, g->og, t*g->g2);
				}
	if (asl->P.ncongroups && y) {
		cscale = asl->i.lscale;
		p = asl->P.cps;
		for(pe = p + n_con; p < pe; p++, y++)
			if ((t = cscale ? *cscale++ * *y : *y))
				for(g = p->g, ge = g + p->ng; g < ge; g++)
					if (g->g2)
						add_op(H, g->og, t*g->g2);
		}
	if ((s = asl->i.vscale))
		for(i = 0; i < n; i++) {
			t = s[i];
			for(j = 0; j <= i; j++)
				*H++ *= t * s[j];
			}
	}