ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
df1b2nv1.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  */
11 #include <df1b2fun.h>
12 #include "admb_messages.h"
13 
18  v(NULL),
19  index_min(1),
20  index_max(0),
21  it(NULL)
22 {
23 }
24 
25 #if !defined(OPT_LIB)
26 
31  {
32  if (i < indexmin() || i > indexmax())
33  {
34  ADMB_ARRAY_BOUNDS_ERROR("Index out of range",
35  "df1b2_init_bounded_number_vector::operator [] (int i)",
36  indexmin(), indexmax(), i);
37  }
38  return v[i];
39  }
40 
46  {
47  if (i < indexmin() || i > indexmax())
48  {
49  ADMB_ARRAY_BOUNDS_ERROR("Index out of range",
50  "df1b2_init_bounded_number_vector::operator () (int i)",
51  indexmin(), indexmax(), i);
52  }
53  return v[i];
54  }
55 #endif
56 
62  {
63  deallocate();
64  }
65 
71  {
72  if(it)
73  {
74  delete it;
75  it=NULL;
76  }
77  if (v)
78  {
79  v+=indexmin();
80  delete [] v;
81  v=NULL;
82  }
83  }
84 
90  const double_index_type & bmin,const double_index_type & bmax,const char * s)
91  {
92  allocate(min1,max1,bmin,bmax,1,s);
93  }
94 
106  int min1, int max1,
107  const double_index_type& bmin,const double_index_type& bmax,
108  const index_type& phase_start, const char* s)
109 {
110  index_min = min1;
111  index_max = max1;
112  unsigned int size =
113  static_cast<unsigned int>(max1 < min1 ? 0 : max1 - min1 + 1);
114  if (size > 0)
115  {
116  v = new df1b2_init_bounded_number[size];
117  if (!v)
118  {
119  cerr << " error trying to allocate memory in "
120  "df1b2_init_bounded_number_vector " << endl;
121  ad_exit(1);
122  }
123  v -= indexmin();
124  for (int i = min1; i <= max1; ++i)
125  {
126  //if (it) v[i].set_initial_value(ad_double((*it)[i]));
127  adstring ss=s + adstring("[") + str(i) + adstring("]");
128  v[i].allocate(ad_double(bmin[i]),ad_double(bmax[i]),
129  ad_integer(phase_start[i]),(char*)(ss) );
130  }
131  }
132  else
133  v=NULL;
134 }
135 
136 /*
137 dvector df1b2_init_number_vector::get_scalefactor(void)
138 {
139  int mmin=indexmin();
140  int mmax=indexmax();
141  dvector s(mmin,mmax);
142  for (int i=mmin;i<=mmax;i++)
143  {
144  s(i)=(*this)(i).get_scalefactor();
145  }
146  return s;
147 }
148 void df1b2_init_number_vector::set_scalefactor(const dvector& s)
149 {
150  int mmin=indexmin();
151  int mmax=indexmax();
152  if (s.indexmin()!=mmin || s.indexmax() != mmax)
153  {
154  cerr << "non matching vector bounds in"
155  " init_number_vector::set_scalefactor" << endl;
156  ad_exit(1);
157  }
158 
159  for (int i=mmin;i<=mmax;i++)
160  {
161  (*this)(i).set_scalefactor(s(i));
162  }
163 }
164 
165 void df1b2_init_number_vector::set_scalefactor(double s)
166 {
167  int mmin=indexmin();
168  int mmax=indexmax();
169  for (int i=mmin;i<=mmax;i++)
170  {
171  (*this)(i).set_scalefactor(s);
172  }
173 }
174 
175 dvector df1b2_init_bounded_number_vector::get_scalefactor(void)
176 {
177  int mmin=indexmin();
178  int mmax=indexmax();
179  dvector s(mmin,mmax);
180  for (int i=mmin;i<=mmax;i++)
181  {
182  s(i)=(*this)(i).get_scalefactor();
183  }
184  return s;
185 }
186 void df1b2_init_bounded_number_vector::set_scalefactor(const dvector& s)
187 {
188  int mmin=indexmin();
189  int mmax=indexmax();
190  if (s.indexmin()!=mmin || s.indexmax() != mmax)
191  {
192  cerr << "non matching vector bounds in"
193  " init_bounded_number_vector::set_scalefactor" << endl;
194  ad_exit(1);
195  }
196 
197  for (int i=mmin;i<=mmax;i++)
198  {
199  (*this)(i).set_scalefactor(s(i));
200  }
201 }
202 
203 void df1b2_init_bounded_number_vector::set_scalefactor(double s)
204 {
205  int mmin=indexmin();
206  int mmax=indexmax();
207  for (int i=mmin;i<=mmax;i++)
208  {
209  (*this)(i).set_scalefactor(s);
210  }
211 }
212 
213 void df1b2_init_bounded_number_vector::set_initial_value(
214  const double_index_type& _it)
215  {
216  it=new double_index_type(_it);
217  }
218 */
219 #if !defined(OPT_LIB)
220 
225  {
226  if (i < indexmin() || i > indexmax())
227  {
228  ADMB_ARRAY_BOUNDS_ERROR("Index out of range",
229  "df1b2_init_number_vector::operator [] (int i)",
230  indexmin(), indexmax(), i);
231  }
232  return v[i];
233  }
234 
240  {
241  if (i < indexmin() || i > indexmax())
242  {
243  ADMB_ARRAY_BOUNDS_ERROR("Index out of range",
244  "df1b2_init_number_vector::operator () (int i)",
245  indexmin(), indexmax(), i);
246  }
247  return v[i];
248  }
249 #endif
250 
255  v(NULL),
256  index_min(0),
257  index_max(-1),
258  it(NULL)
259 {
260 }
265 {
266  deallocate();
267 }
268 
274  {
275  if(it)
276  {
277  delete it;
278  it=NULL;
279  }
280  if (v)
281  {
282  v+=indexmin();
283  delete [] v;
284  v=NULL;
285  }
286  }
287 
292  void df1b2_init_number_vector::allocate(int min1,int max1,
293  const char * s)
294  {
295  allocate(min1,max1,1,s);
296  }
297 
306 void df1b2_init_number_vector::allocate(int min1, int max1,
307  const index_type& phase_start, const char * s)
308 {
309  index_min = min1;
310  index_max = max1;
311  unsigned int size =
312  static_cast<unsigned int>(max1 < min1 ? 0 : max1 - min1 + 1);
313  if (size > 0)
314  {
315  v = new df1b2_init_number[size];
316  if (!v)
317  {
318  cerr << " error trying to allocate memory in "
319  "df1b2_init_number_vector " << endl;
320  ad_exit(1);
321  }
322  v -= indexmin();
323  for (int i=indexmin();i<=indexmax();i++)
324  {
325  //if (it) v[i].set_initial_value(ad_double((*it)[i]));
326  adstring ss=s + adstring("[") + str(i) + adstring("]");
327  v[i].allocate(ad_integer(phase_start[i]),(char*)(ss) );
328  }
329  }
330  else
331  v=NULL;
332 }
Uses polymorphism to get index information from various data types to be used in constructing and all...
Definition: fvar.hpp:7731
df1b2_init_number * v
Definition: df1b2fun.h:1493
~df1b2_init_number_vector()
Destructor.
Definition: df1b2nv1.cpp:264
Stores double value.
Definition: fvar.hpp:8499
exitptr ad_exit
Definition: gradstrc.cpp:53
Description not yet available.
Definition: df1b2fun.h:1526
df1b2_init_number & operator[](int i)
Definition: df1b2fun.h:1503
void deallocate(void)
Description not yet available.
Definition: df1b2nv1.cpp:70
void allocate(int min1, int max1, const double_index_type &bmin, const double_index_type &bmax, const char *s)
Description not yet available.
Definition: df1b2nv1.cpp:89
prnstream & endl(prnstream &)
double_index_type * it
Definition: df1b2fun.h:1553
~df1b2_init_bounded_number_vector()
Description not yet available.
Definition: df1b2nv1.cpp:61
void allocate(const adstring &)
Description not yet available.
Definition: df1b2f15.cpp:262
df1b2_init_bounded_number & operator[](int i)
Definition: df1b2fun.h:1559
df1b2_init_bounded_number_vector()
Default constructor.
Definition: df1b2nv1.cpp:17
double_index_type * it
Definition: df1b2fun.h:1496
#define ADMB_ARRAY_BOUNDS_ERROR(message, function, lower_bounds, upper_bounds, index)
Definition: admb_messages.h:47
df1b2_init_bounded_number & operator()(int i)
Definition: df1b2fun.h:1560
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 index_type &phase_start, const char *s)
Allocate vector of df1b2_init_bounded number with dimension [min1 to max1].
Definition: df1b2nv1.cpp:306
df1b2_init_number_vector()
Default constructor.
Definition: df1b2nv1.cpp:254
Description not yet available.
Definition: df1b2fun.h:1469
Description not yet available.
df1b2_init_bounded_number * v
Definition: df1b2fun.h:1550
void allocate(double _minb, double _maxb, int _phase_start, const char *s="UNNAMED")
Description not yet available.
Definition: df1b2f15.cpp:312
Stores integer.
Definition: fvar.hpp:7654
void deallocate(void)
Description not yet available.
Definition: df1b2nv1.cpp:273
df1b2_init_number & operator()(int i)
Definition: df1b2fun.h:1504
Description not yet available.
Definition: fvar.hpp:8564