3
|
1 // QLD.cc -*- C++ -*- |
|
2 /* |
|
3 |
|
4 Copyright (C) 1992, 1993 John W. Eaton |
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
|
20 Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
21 |
|
22 */ |
|
23 |
238
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include "config.h" |
3
|
26 #endif |
|
27 |
|
28 #include <math.h> |
238
|
29 |
3
|
30 #include "QLD.h" |
|
31 #include "f77-uscore.h" |
|
32 |
|
33 extern "C" |
|
34 { |
|
35 int F77_FCN (qld) (int*, int*, int*, int*, int*, double*, double*, |
|
36 double*, double*, double*, double*, double*, |
|
37 double*, int*, int*, int*, double*, int*, int*, |
|
38 int*); |
|
39 } |
|
40 |
|
41 Vector |
|
42 QLD::minimize (double& objf, int& inform) |
|
43 { |
|
44 int n = x.capacity (); |
|
45 |
|
46 Matrix A1 = lc.eq_constraint_matrix (); |
|
47 Vector b1 = lc.eq_constraint_vector (); |
|
48 |
|
49 Matrix A2 = lc.ineq_constraint_matrix (); |
|
50 Vector b2 = lc.ineq_constraint_vector (); |
|
51 |
|
52 int me = A1.rows (); |
|
53 int m = me + A2.rows (); |
|
54 |
|
55 cout << "n: " << n << "\n"; |
|
56 cout << "m: " << m << "\n"; |
|
57 cout << "me: " << me << "\n"; |
|
58 |
|
59 A1.stack (A2); |
|
60 b1.stack (b2); |
|
61 |
|
62 int lwar = n*(3*n + 15)/2 + m + 100; |
|
63 int liwar = n + 100; |
|
64 |
|
65 double *war = new double [lwar]; |
|
66 int *iwar = new int [liwar]; |
|
67 |
|
68 iwar[0] = 0; |
|
69 |
|
70 double *u = new double [m+n+n + 100]; |
|
71 |
|
72 int iout = 0; |
|
73 |
|
74 double *px = x.fortran_vec (); |
|
75 double *ph = H.fortran_vec (); |
|
76 |
|
77 cout << x; |
|
78 cout << H; |
|
79 cout << c; |
|
80 |
|
81 double *pc = (double *) NULL; |
|
82 if (c.capacity () > 0) |
|
83 pc = c.fortran_vec (); |
|
84 |
|
85 double *pa = (double *) NULL; |
|
86 if (A1.rows () > 0 && A1.columns () > 0) |
|
87 pa = A1.fortran_vec (); |
|
88 |
|
89 double *pb = (double *) NULL; |
|
90 if (b1.capacity () > 0) |
|
91 pb = b1.fortran_vec (); |
|
92 |
|
93 Vector xlb = bnds.lower_bounds (); |
|
94 Vector xub = bnds.upper_bounds (); |
|
95 if (xlb.capacity () <= 0) |
|
96 { |
|
97 xlb.resize (n, -1.0e30); |
|
98 xub.resize (n, 1.0e30); |
|
99 } |
|
100 double *pxl = xlb.fortran_vec (); |
|
101 double *pxu = xub.fortran_vec (); |
|
102 |
|
103 int mmax = m > 0 ? m : 1; |
|
104 |
|
105 iprint = 1; |
|
106 F77_FCN (qld) (&m, &me, &mmax, &n, &n, ph, pc, pa, pb, pxl, pxu, px, |
|
107 u, &iout, &inform, &iprint, war, &lwar, iwar, &liwar); |
|
108 |
|
109 delete war; |
|
110 delete iwar; |
|
111 delete u; |
|
112 |
|
113 objf = (x.transpose () * H * x) / 2.0; |
|
114 if (c.capacity () > 0) |
|
115 objf += c.transpose () * x; |
|
116 |
|
117 return x; |
|
118 } |
|
119 |
|
120 void |
|
121 QLD::set_default_options (void) |
|
122 { |
|
123 iprint = 0; |
|
124 } |
|
125 |
|
126 /* |
|
127 ;;; Local Variables: *** |
|
128 ;;; mode: C++ *** |
|
129 ;;; page-delimiter: "^/\\*" *** |
|
130 ;;; End: *** |
|
131 */ |