ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
fquadpri.cpp
Go to the documentation of this file.
1 /*
2  * $Id$
3  *
4  * Author: David Fournier
5  * Copyright (c) 2008-2012 Regents of the University of California
6  */
7 #include <df1b2fun.h>
8 #ifndef OPT_LIB
9  #include <cassert>
10  #include <climits>
11 #endif
12 
13 // this should be a resizeable array
15 
18 
19 
21 {
23  {
24  cerr << "Error[" << __FILE__ << ':' << __LINE__
25  << "]: Max size exceeded.\n";
26  ad_exit(1);
27  }
28  else
29  {
31  ptr[num_quadratic_prior++]=this;
32  }
33 }
35 {
36  bool isallocated = Lxu && allocated(*Lxu) && index;
37 #ifndef OPT_LIB
38  assert(isallocated);
39 #endif
40  if (isallocated)
41  {
42  int mmin=(*pu)(pu->indexmin()).get_ind_index();
43  int size=pu->size();
44  int offset=mmin-M(M.indexmin()).indexmax()-1; // subtract x offset
45  int nvar = index->indexmax();
46  {
47  switch(old_style_flag)
48  {
49  case 0:
50  for (int i=1;i<=nvar;i++)
51  {
52  int jcol=(*index)(i);
53  for (int ii=1;ii<=size;ii++)
54  {
55  M(ii+offset,jcol)+=(*Lxu)(i,ii);
56  }
57  }
58  break;
59  case 1:
60  break;
72  case 2:
73  for (int i=1;i<=nvar;i++)
74  {
75  int jcol=(*index)(i);
76  for (int ii=1;ii<=size;ii++)
77  {
78  M(ii+offset,jcol)+=(*Lxu)(i,ii);
79  }
80  }
81  break;
82  default:
83  cerr << "Illegal valueinswitch statement" << endl;
84  ad_exit(1);
85  }
86  }
87  }
88 }
93  CM(NULL)
94 {
95  add_to_list();
97  M = NULL;
98  pu = NULL;
99  index = NULL;
100  Lxu = NULL;
101 }
106 {
107  if (index)
108  {
109  delete index;
110  index = NULL;
111  }
112  if (Lxu)
113  {
114  delete Lxu;
115  Lxu = NULL;
116  }
117  if (M)
118  {
119  delete M;
120  M = NULL;
121  }
122  if (pu)
123  {
124  delete pu;
125  pu = NULL;
126  }
127 }
128 
130  const char* s)
131  {
132  allocate(_u);
133  }
135  const df1b2_init_vector & _u, const char * s)
136  {
137  allocate(_M,_u);
138  }
140  {
141  pu = new df1b2_init_vector(_u);
142  }
144  const df1b2_init_vector & _u)
145  {
146  M =new df1b2matrix(_M);
147  pu = new df1b2_init_vector(_u);
148  }
150  {
154  dvector cu=value(*pu);
155 
157  {
159  df1b2vector v(M.indexmin(),M.indexmax());
161  switch (old_style_flag)
162  {
163  case 0:
164  case 1:
165  v = solve(M,cu);
166  break;
167  case 2:
168  v = M*cu;
169  break;
170  default:
171  cerr << "Illegal value for quadratic_prior::old_style_flag"
172  << endl;
173  ad_exit(1);
174  }
175  int mmin=v.indexmin();
176  int mmax=v.indexmax();
177 
178 #ifndef OPT_LIB
179  assert(num_active_parameters <= INT_MAX);
180 #endif
181  if (index)
182  {
183  if (index->indexmax() != (int)num_active_parameters)
184  {
185  delete index;
186  index=0;
187  }
188  }
189 
190  if (num_active_parameters>0)
191  {
192  if (!index)
193  {
195  }
196  if (Lxu)
197  {
198  int tmin = Lxu->indexmin();
199  if ((Lxu->indexmin() != mmin)
200  || (Lxu->indexmax() != mmax)
201  || ((*Lxu)(tmin).indexmin() != 1)
202  || ((*Lxu)(tmin).indexmax() != (int)num_active_parameters))
203  {
204  delete Lxu;
205  Lxu=0;
206  }
207  }
208  if (!Lxu)
209  {
210  Lxu=new dmatrix(1, (int)num_active_parameters, mmin-1, mmax);
211  }
212  for (int i=1;i<=(int)num_active_parameters;i++)
213  {
214  (*Lxu)(i,mmin-1)=(*funnel_init_var::plist)(i,1);
215  }
216  for (int j=mmin;j<=mmax;j++)
217  {
218  for (int i=1;i<=(int)num_active_parameters;i++)
219  {
220  switch (old_style_flag)
221  {
222  case 0:
223  (*Lxu)(i,j)=v(j).get_u_dot()[i-1];
224  break;
225  case 1:
226  case 2:
227  (*Lxu)(i,j)=2.0*v(j).get_u_dot()[i-1];
228  break;
229  default:
230  cerr << "Illegal value for quadratic_prior::old_style_flag"
231  << endl;
232  ad_exit(1);
233  }
234  }
235  }
236  }
237  else
238  {
239  if (Lxu)
240  {
241  delete Lxu;
242  Lxu=0;
243  }
244  }
245  }
247  }
248 
250  {
251  for (int i=0;i<num_quadratic_prior;i++)
252  {
253  //cout << ptr[i]->get_num_active_parameters() << endl;
254  //if (ptr[i]->get_num_active_parameters()>0)
255  {
256  ptr[i]->get_Lxu(M);
257  }
258  }
259  }
260 
262 {
264 }
265 
267 {
268  old_style_flag=0;
269 }
276 {
278 }
280 {
281  old_style_flag=2;
282 }
289 {
291 }
298 {
300 }
301 
303 {
305 }
306 // *******************************************************
307 // *******************************************************
308 // *******************************************************
309 // *******************************************************
311 {
313 }
314 
316 {
317  old_style_flag=2;
318 }
320 {
321  //df1b2quadratic_prior::operator = (M);
322 }
324 {
328  dvector cu=value(*pu);
329 
331  {
332  //df1b2variable::noallocate=1;
333  //df1b2vector v(M.indexmin(),M.indexmax());
335  switch (old_style_flag)
336  {
337  case 0:
338  case 1:
339  cout << "this can't happen" << endl;
340  ad_exit(1);
341  break;
342  case 2:
343  //v = M*cu;
344  break;
345  default:
346  cerr << "Illegal value for quadratic_prior::old_style_flag"
347  << endl;
348  ad_exit(1);
349  }
350  //int mmin=v.indexmin();
351  //int mmax=v.indexmax();
352 
353  if (index)
354  {
355  //if (index->indexmax() != nvar)
356  cout << "this can't happen" << endl;
357  ad_exit(1);
358  delete index;
359  index=0;
360  }
361 
362  if (Lxu)
363  {
364  cout << "this can't happen" << endl;
365  ad_exit(1);
366  delete Lxu;
367  Lxu=0;
368  }
369  }
371 }
372 
373 
void operator=(const dmatrix &M)
Definition: fquadpri.cpp:319
Description not yet available.
Definition: df1b2fun.h:1947
static const int max_num_quadratic_prior
Definition: df1b2fun.h:1958
void operator=(const df1b2matrix &M)
Assigns df1v2quadratic_re with values from m.
Definition: fquadpri.cpp:288
~df1b2quadratic_prior(void)
Destructor.
Definition: fquadpri.cpp:105
df1b2_init_vector * pu
Definition: df1b2fun.h:1954
static int num_quadratic_prior
Definition: df1b2fun.h:1957
static void get_Lxu_contribution(dmatrix &)
Definition: fquadpri.cpp:249
int allocated(const ivector &v)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: fvar_a59.cpp:13
Vector of double precision numbers.
Definition: dvector.h:50
int indexmin(void) const
Definition: df1b2fun.h:1054
Description not yet available.
Definition: df1b2fun.h:1401
int indexmin() const
Definition: fvar.hpp:2917
static int noallocate
Definition: df1b2fun.h:294
Description not yet available.
Definition: df1b2fun.h:953
virtual void get_Lxu(dmatrix &)=0
Definition: fquadpri.cpp:34
df1b2matrix * M
Definition: df1b2fun.h:1950
exitptr ad_exit
Definition: gradstrc.cpp:53
int indexmin(void) const
Definition: df1b2fun.h:969
virtual void set_old_style_flag(void)
Definition: fquadpri.cpp:279
void add_to_list(void)
Definition: fquadpri.cpp:20
dvector solve(const dmatrix &aa, const dvector &z)
Solve a linear system using LU decomposition.
Definition: dmat34.cpp:46
prnstream & endl(prnstream &)
Array of integers(int) with indexes from index_min to indexmax.
Definition: ivector.h:50
void operator=(const df1b2matrix &)
Definition: fquadpri.cpp:149
static int no_derivatives
Definition: df1b2fun.h:759
static imatrix * plist
Definition: df1b2fnl.h:69
virtual void set_old_style_flag(void)
Definition: fquadpri.cpp:315
#define M
Definition: rngen.cpp:57
df1b2quadratic_prior(void)
Default constructor.
Definition: fquadpri.cpp:92
int indexmax() const
Definition: ivector.h:104
Description not yet available.
Definition: fvar.hpp:2819
static df1b2quadratic_prior * ptr[]
Definition: df1b2fun.h:1956
unsigned int num_active_parameters
Definition: df1b2fun.h:1962
int indexmax() const
Definition: fvar.hpp:2921
Description not yet available.
Definition: df1b2fun.h:1042
int indexmax(void) const
Definition: df1b2fun.h:1055
Description not yet available.
dvector column(const dmatrix &matrix, int j)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: dmat6.cpp:13
void operator=(const df1b2matrix &M)
Assigns normal_df1b2quadratic_prior with values from m.
Definition: fquadpri.cpp:275
dvector value(const df1_one_vector &v)
Definition: df11fun.cpp:69
static unsigned int num_vars
Definition: df1b2fnl.h:64
virtual void set_old_style_flag(void)
Definition: fquadpri.cpp:266
int size()
Definition: df1b2fun.h:971
void allocate(const df1b2_init_vector &_u, const char *s)
Definition: fquadpri.cpp:129
static int in_qp_calculations
Definition: df1b2fun.h:1909