ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
model48.cpp
Go to the documentation of this file.
1 
5 #include <admodel.h>
6 
13  const double_index_type& initial_value)
14 {
15  if (it)
16  {
17  delete it;
18  it = 0;
19  }
20  it = new double_index_type(initial_value);
21 
22  if (v)
23  {
24  int mmin = indexmin();
25  int mmax = indexmax();
26  for (int i = mmin; i <= mmax; ++i)
27  {
28  v[i] = ad_double(initial_value(i));
29  }
30  }
31 }
34  v(nullptr),
35  index_min(1),
36  index_max(0),
37  it(nullptr)
38 {
39 }
42 {
43  deallocate();
44 }
47 {
48  if (it)
49  {
50  delete it;
51  it = NULL;
52  }
53  if (v)
54  {
55  v += indexmin();
56  delete [] v;
57  v = NULL;
58  }
59  index_min = 1;
60  index_max = 0;
61 }
67  const char *s)
68 {
69  int min1 = m.rowmin();
70  int max1 = m.rowmax();
71  double_index_type bmin = column(m,1);
72  double_index_type bmax = column(m,2);
73  index_type phz1 = ivector(column(m,3));
74  allocate(min1,max1,bmin,bmax,phz1,s);
75 }
89  int min1,
90  int max1,
91  const double_index_type& bmin,
92  const double_index_type& bmax,
93  const char* s)
94 {
95  allocate(min1, max1, bmin, bmax, 1, s);
96 }
109  int min1,
110  int max1,
111  const double_index_type& bmin,
112  const double_index_type& bmax,
113  const index_type& phase_start,
114  const char* s)
115 {
116  if (max1 >= min1)
117  {
119  static_cast<unsigned int>(max1 - min1 + 1)];
120  if (!v)
121  {
122  cerr << " error trying to allocate memory in "
123  << "param_init_bounded_number_vector " << endl;
124  ad_exit(1);
125  }
126  index_min = min1;
127  index_max = max1;
128  v -= indexmin();
129  for (int i = indexmin(); i <= indexmax(); ++i)
130  {
131  if (it) v[i].set_initial_value(ad_double((*it)[i]));
132  adstring ss=s + adstring("[") + str(i) + adstring("]");
133  v[i].allocate(ad_double(bmin[i]),ad_double(bmax[i]),
134  ad_integer(phase_start[i]),(char*)(ss) );
135  }
136  }
137 }
142 {
143  int mmin = indexmin();
144  int mmax = indexmax();
145  dvector scalefactors(mmin, mmax);
146  for (int i = mmin; i <= mmax; ++i)
147  {
148  scalefactors(i) = (*this)(i).get_scalefactor();
149  }
150  return scalefactors;
151 }
158 {
159  int mmin = indexmin();
160  int mmax = indexmax();
161  if (scalefactors.indexmin() != mmin || scalefactors.indexmax() != mmax)
162  {
163  cerr << "non matching vector bounds in"
164  << " init_number_vector::set_scalefactor" << endl;
165  ad_exit(1);
166  }
167  for (int i = mmin; i <= mmax; ++i)
168  {
169  (*this)(i).set_scalefactor(scalefactors(i));
170  }
171 }
178 {
179  int mmin = indexmin();
180  int mmax = indexmax();
181  for (int i = mmin; i <= mmax; ++i)
182  {
183  (*this)(i).set_scalefactor(scalefactor);
184  }
185 }
186 
188 {
189  int mmin=indexmin();
190  int mmax=indexmax();
191  dvector s(mmin,mmax);
192  for (int i=mmin;i<=mmax;i++)
193  {
194  s(i)=(*this)(i).get_scalefactor();
195  }
196  return s;
197 }
199 {
200  int mmin=indexmin();
201  int mmax=indexmax();
202  if (s.indexmin()!=mmin || s.indexmax() != mmax)
203  {
204  cerr << "non matching vector bounds in"
205  " init_vector_vector::set_scalefactor" << endl;
206  ad_exit(1);
207  }
208 
209  for (int i=mmin;i<=mmax;i++)
210  {
211  (*this)(i).set_scalefactor(s(i));
212  }
213 }
214 
216 {
217  int mmin=indexmin();
218  int mmax=indexmax();
219  for (int i=mmin;i<=mmax;i++)
220  {
221  (*this)(i).set_scalefactor(s);
222  }
223 }
224 
226 {
227  int mmin=indexmin();
228  int mmax=indexmax();
229  dvector s(mmin,mmax);
230  for (int i=mmin;i<=mmax;i++)
231  {
232  s(i)=(*this)(i).get_scalefactor();
233  }
234  return s;
235 }
237 {
238  int mmin=indexmin();
239  int mmax=indexmax();
240  if (s.indexmin()!=mmin || s.indexmax() != mmax)
241  {
242  cerr << "non matching vector bounds in"
243  " init_matrix_vector::set_scalefactor" << endl;
244  ad_exit(1);
245  }
246 
247  for (int i=mmin;i<=mmax;i++)
248  {
249  (*this)(i).set_scalefactor(s(i));
250  }
251 }
252 
254 {
255  int mmin=indexmin();
256  int mmax=indexmax();
257  for (int i=mmin;i<=mmax;i++)
258  {
259  (*this)(i).set_scalefactor(s);
260  }
261 }
262 
264 {
265  int mmin=indexmin();
266  int mmax=indexmax();
267  dvector s(mmin,mmax);
268  for (int i=mmin;i<=mmax;i++)
269  {
270  s(i)=(*this)(i).get_scalefactor();
271  }
272  return s;
273 }
275 {
276  int mmin=indexmin();
277  int mmax=indexmax();
278  if (s.indexmin()!=mmin || s.indexmax() != mmax)
279  {
280  cerr << "non matching vector bounds in"
281  " init_bounded_number_vector::set_scalefactor" << endl;
282  ad_exit(1);
283  }
284 
285  for (int i=mmin;i<=mmax;i++)
286  {
287  (*this)(i).set_scalefactor(s(i));
288  }
289 }
290 
292 {
293  int mmin=indexmin();
294  int mmax=indexmax();
295  for (int i=mmin;i<=mmax;i++)
296  {
297  (*this)(i).set_scalefactor(s);
298  }
299 }
300 
302 {
303  int mmin=indexmin();
304  int mmax=indexmax();
305  dvector s(mmin,mmax);
306  for (int i=mmin;i<=mmax;i++)
307  {
308  s(i)=(*this)(i).get_scalefactor();
309  }
310  return s;
311 }
313 {
314  int mmin=indexmin();
315  int mmax=indexmax();
316  if (s.indexmin()!=mmin || s.indexmax() != mmax)
317  {
318  cerr << "non matching vector bounds in"
319  " init_bounded_vector_vector::set_scalefactor" << endl;
320  ad_exit(1);
321  }
322 
323  for (int i=mmin;i<=mmax;i++)
324  {
325  (*this)(i).set_scalefactor(s(i));
326  }
327 }
328 
330 {
331  int mmin=indexmin();
332  int mmax=indexmax();
333  for (int i=mmin;i<=mmax;i++)
334  {
335  (*this)(i).set_scalefactor(s);
336  }
337 }
338 
340 {
341  int mmin=indexmin();
342  int mmax=indexmax();
343  dvector s(mmin,mmax);
344  for (int i=mmin;i<=mmax;i++)
345  {
346  s(i)=(*this)(i).get_scalefactor();
347  }
348  return s;
349 }
351 {
352  int mmin=indexmin();
353  int mmax=indexmax();
354  if (s.indexmin()!=mmin || s.indexmax() != mmax)
355  {
356  cerr << "non matching vector bounds in"
357  " init_bounded_matrix_vector::set_scalefactor" << endl;
358  ad_exit(1);
359  }
360 
361  for (int i=mmin;i<=mmax;i++)
362  {
363  (*this)(i).set_scalefactor(s(i));
364  }
365 }
366 
368 {
369  int mmin=indexmin();
370  int mmax=indexmax();
371  for (int i=mmin;i<=mmax;i++)
372  {
373  (*this)(i).set_scalefactor(s);
374  }
375 }
Uses polymorphism to get index information from various data types to be used in constructing and all...
Definition: fvar.hpp:7731
void set_scalefactor(double s)
Definition: model48.cpp:215
void set_scalefactor(double s)
Sets scalefactor for param_init_number_vector.
Definition: model48.cpp:177
~param_init_bounded_number_vector()
Destructor.
Definition: model48.cpp:41
void allocate(double _minb, double _maxb, int phase_start=1, const char *s="UNNAMED")
Definition: model.cpp:489
Vector of double precision numbers.
Definition: dvector.h:50
int indexmin() const
Get minimum valid index.
Definition: dvector.h:199
void set_initial_value(const double_index_type &it)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: model48.cpp:12
int indexmin() const
Definition: admodel.h:2901
Stores double value.
Definition: fvar.hpp:8499
exitptr ad_exit
Definition: gradstrc.cpp:53
void set_initial_value(double x)
Definition: model.cpp:90
void deallocate()
Deallocate param_init_bounded_number_vector memory.
Definition: model48.cpp:46
Description not yet available.
Definition: admodel.h:1228
void set_scalefactor(double s)
Definition: model48.cpp:253
prnstream & endl(prnstream &)
Array of integers(int) with indexes from index_min to indexmax.
Definition: ivector.h:50
int rowmax() const
Definition: fvar.hpp:2929
int indexmax() const
Get maximum valid index.
Definition: dvector.h:204
int indexmin() const
Definition: admodel.h:2803
Description not yet available.
dvector get_scalefactor(void)
Returns vector of scalefactor values.
Definition: model48.cpp:141
int indexmax() const
Definition: admodel.h:2804
param_init_bounded_number * v
Definition: admodel.h:2917
param_init_bounded_number_vector()
Default constructor.
Definition: model48.cpp:33
adstring str(double x, int minwidth=17, int decplaces=-1)
Convert x to adstring with minimum width and total number of decimal places.
Definition: str.cpp:25
void allocate(int min1, int max1, const double_index_type &bmin, const double_index_type &bmax, const index_type &phase_start, const char *s)
Allocate vector of param_init_bounded_number with dimension [min1 to max1] and bounded by [bmin...
Definition: model48.cpp:108
Description not yet available.
Definition: admodel.h:1589
int indexmax() const
Definition: admodel.h:2902
dvector column(const dmatrix &matrix, int j)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: dmat6.cpp:13
dvector get_scalefactor(void)
Definition: model48.cpp:187
Stores integer.
Definition: fvar.hpp:7654
dvector get_scalefactor(void)
Definition: model48.cpp:225
int rowmin() const
Definition: fvar.hpp:2925
Description not yet available.
Definition: fvar.hpp:8564
double_index_type * it
Definition: admodel.h:2920