3
|
1 // QLD.cc -*- C++ -*- |
|
2 /* |
|
3 |
1011
|
4 Copyright (C) 1992, 1993, 1994, 1995 John W. Eaton |
3
|
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 |
1192
|
25 #include <config.h> |
3
|
26 #endif |
|
27 |
|
28 #include <math.h> |
461
|
29 #include <iostream.h> |
238
|
30 |
461
|
31 #include "dMatrix.h" |
|
32 #include "dColVector.h" |
|
33 #include "dRowVector.h" |
3
|
34 #include "QLD.h" |
|
35 #include "f77-uscore.h" |
|
36 |
|
37 extern "C" |
|
38 { |
|
39 int F77_FCN (qld) (int*, int*, int*, int*, int*, double*, double*, |
|
40 double*, double*, double*, double*, double*, |
|
41 double*, int*, int*, int*, double*, int*, int*, |
|
42 int*); |
|
43 } |
|
44 |
|
45 Vector |
|
46 QLD::minimize (double& objf, int& inform) |
|
47 { |
|
48 int n = x.capacity (); |
|
49 |
|
50 Matrix A1 = lc.eq_constraint_matrix (); |
|
51 Vector b1 = lc.eq_constraint_vector (); |
|
52 |
|
53 Matrix A2 = lc.ineq_constraint_matrix (); |
|
54 Vector b2 = lc.ineq_constraint_vector (); |
|
55 |
|
56 int me = A1.rows (); |
|
57 int m = me + A2.rows (); |
|
58 |
|
59 cout << "n: " << n << "\n"; |
|
60 cout << "m: " << m << "\n"; |
|
61 cout << "me: " << me << "\n"; |
|
62 |
|
63 A1.stack (A2); |
|
64 b1.stack (b2); |
|
65 |
|
66 int lwar = n*(3*n + 15)/2 + m + 100; |
|
67 int liwar = n + 100; |
|
68 |
|
69 double *war = new double [lwar]; |
|
70 int *iwar = new int [liwar]; |
|
71 |
|
72 iwar[0] = 0; |
|
73 |
|
74 double *u = new double [m+n+n + 100]; |
|
75 |
|
76 int iout = 0; |
|
77 |
|
78 double *px = x.fortran_vec (); |
|
79 double *ph = H.fortran_vec (); |
|
80 |
|
81 cout << x; |
|
82 cout << H; |
|
83 cout << c; |
|
84 |
461
|
85 double *pc = 0; |
3
|
86 if (c.capacity () > 0) |
|
87 pc = c.fortran_vec (); |
|
88 |
461
|
89 double *pa = 0; |
3
|
90 if (A1.rows () > 0 && A1.columns () > 0) |
|
91 pa = A1.fortran_vec (); |
|
92 |
461
|
93 double *pb = 0; |
3
|
94 if (b1.capacity () > 0) |
|
95 pb = b1.fortran_vec (); |
|
96 |
|
97 Vector xlb = bnds.lower_bounds (); |
|
98 Vector xub = bnds.upper_bounds (); |
|
99 if (xlb.capacity () <= 0) |
|
100 { |
|
101 xlb.resize (n, -1.0e30); |
|
102 xub.resize (n, 1.0e30); |
|
103 } |
|
104 double *pxl = xlb.fortran_vec (); |
|
105 double *pxu = xub.fortran_vec (); |
|
106 |
|
107 int mmax = m > 0 ? m : 1; |
|
108 |
|
109 iprint = 1; |
|
110 F77_FCN (qld) (&m, &me, &mmax, &n, &n, ph, pc, pa, pb, pxl, pxu, px, |
|
111 u, &iout, &inform, &iprint, war, &lwar, iwar, &liwar); |
|
112 |
|
113 delete war; |
|
114 delete iwar; |
|
115 delete u; |
|
116 |
|
117 objf = (x.transpose () * H * x) / 2.0; |
|
118 if (c.capacity () > 0) |
|
119 objf += c.transpose () * x; |
|
120 |
|
121 return x; |
|
122 } |
|
123 |
|
124 void |
|
125 QLD::set_default_options (void) |
|
126 { |
|
127 iprint = 0; |
|
128 } |
|
129 |
|
130 /* |
|
131 ;;; Local Variables: *** |
|
132 ;;; mode: C++ *** |
|
133 ;;; page-delimiter: "^/\\*" *** |
|
134 ;;; End: *** |
|
135 */ |