File: objconst.c

package info (click to toggle)
libamplsolver 0~20190702-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 3,156 kB
  • sloc: ansic: 40,471; asm: 76; sh: 72; fortran: 51; makefile: 16
file content (72 lines) | stat: -rw-r--r-- 2,250 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
/*******************************************************************
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.
*******************************************************************/

/* For LPs (and IPs and MIPs), objconst(n) is the constant term
 * for objective n (first objective has n = 0).
 */
#define SKIP_NL2_DEFINES
#include "nlp.h"
#include "nlp2.h"
#include "asl_pfg.h"
#include "asl_pfgh.h"
#include "obj_adj.h"
#undef f_OPNUM
#include "r_opn0.hd"	/* for f_OPNUM */

 real
#ifdef KR_headers
objconst_ASL(asl, n) ASL *asl; int n;
#else
objconst_ASL(ASL *asl, int n)
#endif
{
	Objrep *r, **rp;
	expr_n *e;
	efunc_n *opnum = f_OPNUM_ASL;
	real c;
	static char who[] = "objconst";

	if (!asl)
		badasl_ASL(asl,0,who);
	else if (asl->i.ASLtype < ASL_read_f || asl->i.ASLtype >ASL_read_pfgh)
		badasl_ASL(asl,ASL_read_f,who);

	c = 0.;
	if (n >= 0 && n < n_obj) {
		if ((rp = asl->i.Or) && (r = rp[n]))
			c = r->c0a;
		switch(asl->i.ASLtype) {
		  case ASL_read_fgh:
			e = (expr_n*)(((ASL_fgh*)asl)->I.obj2_de_ + n)->e;
			break;
		  case ASL_read_pfg:
			e = (expr_n*)(((ASL_pfg*)asl)->I.obj_de_ + n)->e;
			opnum = (efunc_n*)f_OPNUM;
			break;
		  case ASL_read_pfgh:
			e = (expr_n*)(((ASL_pfgh*)asl)->I.obj2_de_ + n)->e;
			opnum = (efunc_n*)f_OPNUM;
			break;
		  default:
			e = (expr_n*)(((ASL_fg*)asl)->I.obj_de_ + n)->e;
		  }
		if (e->op == opnum || e->op == (efunc_n *)f_OPNUM)
			return e->v;
		}
	return c;
	}