ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
model21.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 <admodel.h>
8 /*
9 void param_init_d3array::set_simulation_bounds(const dmatrix& symbds,
10  const int& ii)
11 {
12  cerr << " Error -- void param_init_d3array::set_simulation_bounds"
13  " (const dmatrix& symbds, const int& ii) has not yet been defined" << endl;
14  exit(1);
15 }
16 */
17 
19  const int& ii)
20 {
21  cerr << " Error -- "
22  " void param_init_number::add_value(const dvector& ndev, const int& ii)"
23  " has not yet been defined" << endl;
24  ad_exit(1);
25 }
26 
27 const char * param_init_d3array::label(void)
28 {
29  return model_name_tag::label().mychar();
30 }
31 
34 {
35  //add_to_list();
36 }
37 
41 unsigned int param_init_d3array::size_count() const
42 {
43  return ::size_count(*this);
44 }
45 
46 void param_init_d3array::save_value(ofstream& ofs)
47 {
48  if (!(!(*this)))
49  ofs << label_class(this->label()) << dvar3_array(*this) << endl;
50 }
51 
53 {
54  if (!(!(*this)))
55  {
56  dvar3_array& tmp = *this;
57  uos << tmp;
58  }
59 }
60 
62  const int& ii, const dvariable& pen)
63  {
64  ::set_value(*this,x,ii);
65  }
66 
67 void param_init_d3array::set_value_inv(const dvector& x, const int& ii)
68  {
69  ::set_value_inv(*this,x,ii);
70  }
71 
73  {
74  ::copy_value_to_vector(*this,x,ii);
75  }
76 
78  const int& ii)
79  {
80  ::restore_value_from_vector(*this,x,ii);
81  }
82 
83 void param_init_d3array::save_value(const ofstream& _ofs,int prec)
84  {
85  ofstream& ofs=(ofstream&) _ofs;
86  ofs << setw(prec+6) << setprecision(prec) << dvar3_array(*this) << endl;
87  }
88 
94 void param_init_d3array::allocate(int smin, int smax, int rmin, int rmax,
95  int cmin, int cmax, const char* s)
96 {
97  allocate(smin, smax, rmin, rmax, cmin, cmax, 1, s);
98 }
105  const ad_integer& sh,const index_type& nrl,const index_type& nrh,
106  const index_type& ncl,const index_type& nch,const char * s)
107 {
108  allocate(sl, sh, nrl, nrh, ncl, nch, 1, s);
109 }
116  const ad_integer& sl, const ad_integer& sh,
117  const index_type& nrl, const index_type& nrh,
118  const index_type& ncl, const index_type& nch,
119  int _phase_start, const char * s)
120 {
121  named_dvar3_array::allocate(sl,sh,nrl,nrh,ncl,nch,s);
122  initial_params::allocate(_phase_start);
123  if (!(!(*this)))
124  {
125  for (int i=indexmin();i<=indexmax();i++)
126  {
127  if (allocated((*this)(i)))
128  {
129  for (int j=(*this)(i).indexmin();j<=(*this)(i).indexmax();j++)
130  {
131  if (allocated((*this)(i,j)))
132  {
134  {
135  *(ad_comm::global_bparfile) >> (*this)(i,j);
136  }
137  else if (ad_comm::global_parfile)
138  {
139  *(ad_comm::global_parfile) >> (*this)(i,j);
140  }
141  else
142  {
143  (*this)(i,j)=(initial_value);
144  }
145  }
146  }
147  }
148  }
149  }
150 }
156 void param_init_d3array::allocate( int smin, int smax, int rmin, int rmax,
157  int cmin, int cmax, int _phase_start, const char* s)
158 {
159  named_dvar3_array::allocate(smin,smax,rmin,rmax,cmin,cmax,s);
160  initial_params::allocate(_phase_start);
161  if (!(!(*this)))
162  {
163  for (int i=indexmin();i<=indexmax();i++)
164  {
165  if (allocated((*this)(i)))
166  {
168  {
169  *(ad_comm::global_bparfile) >> (*this)(i);
170  }
171  else if (ad_comm::global_parfile)
172  {
173  *(ad_comm::global_parfile) >> (*this)(i);
174  }
175  else
176  {
177  (*this)(i) = (initial_value);
178  }
179  }
180  }
181  }
182 }
183 
185  const int& _ii)
186  {
187  int& ii=(int&) _ii;
188  dvector& v=(dvector&) _v;
189  int smin=slicemin();
190  int smax=slicemax();
191  for (int k=smin;k<=smax;k++)
192  {
193  int mmin=(*this)(k).rowmin();
194  int mmax=(*this)(k).rowmax();
195  for (int i=mmin;i<=mmax;i++)
196  {
197  int cmin=((*this)(k,i)).indexmin();
198  int cmax=((*this)(k,i)).indexmax();
199  for (int j=cmin;j<=cmax;j++)
200  {
201  v(ii++)=0.;
202  }
203  }
204  }
205  }
206 
208  const int& _ii)
209  {
210  int& ii=(int&) _ii;
211  dvector& v=(dvector&) _v;
212  int smin=slicemin();
213  int smax=slicemax();
214  for (int k=smin;k<=smax;k++)
215  {
216  int mmin=(*this)(k).rowmin();
217  int mmax=(*this)(k).rowmax();
218  for (int i=mmin;i<=mmax;i++)
219  {
220  int cmin=((*this)(k,i)).indexmin();
221  int cmax=((*this)(k,i)).indexmax();
222  for (int j=cmin;j<=cmax;j++)
223  {
224  v(ii++)=0.;
225  }
226  }
227  }
228  }
229 
231  const int& _ii)
232  {
233  int& ii=(int&) _ii;
234  dvector& v=(dvector&) _v;
235  if (allocated(*this))
236  {
237  int smin=slicemin();
238  int smax=slicemax();
239  for (int k=smin;k<=smax;k++)
240  {
241  if (allocated((*this)(k)))
242  {
243  int mmin=(*this)(k).rowmin();
244  int mmax=(*this)(k).rowmax();
245  for (int i=mmin;i<=mmax;i++)
246  {
247  if (allocated((*this)(k,i)))
248  {
249  int cmin=((*this)(k,i)).indexmin();
250  int cmax=((*this)(k,i)).indexmax();
251  for (int j=cmin;j<=cmax;j++)
252  {
253  v(ii++)=1.;
254  }
255  }
256  }
257  }
258  }
259  }
260  }
261 
263 {
264  cifstream& s=(cifstream&) _s;
265  s >> dvar3_array(m);
266  return s;
267 }
268 
269 void param_init_d3array::restore_value(const ifstream& ofs)
270 {
271  ofs >> dvar3_array(*this);
272 }
virtual void set_value(const dvar_vector &x, const int &ii, const dvariable &pen)
Definition: model21.cpp:61
Uses polymorphism to get index information from various data types to be used in constructing and all...
Definition: fvar.hpp:7731
int slicemin() const
Definition: fvar.hpp:4274
label_class label(void)
Definition: admodel.h:172
virtual void sd_scale(const dvector &d, const dvector &x, const int &ii)
Definition: model21.cpp:230
#define x
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
virtual void restore_value_from_vector(const dvector &, const int &)
Definition: model21.cpp:77
const char * mychar(void)
Definition: admodel.h:156
int slicemax() const
Definition: fvar.hpp:4275
static uistream * global_bparfile
Definition: fvar.hpp:8859
exitptr ad_exit
Definition: gradstrc.cpp:53
ADMB variable vector.
Definition: fvar.hpp:2172
Description not yet available.
Definition: admodel.h:814
param_init_d3array(void)
Definition: model21.cpp:32
int indexmax() const
Definition: fvar.hpp:4273
virtual void bsave_value(uostream &uos)
Definition: model21.cpp:52
virtual unsigned int size_count() const
Return number of active parameters.
Definition: model21.cpp:41
Description not yet available.
Definition: admodel.h:2470
virtual void set_value_inv(const dvector &x, const int &ii)
Definition: model21.cpp:67
dvar3_array(void)
Default constructor.
Definition: f3arr17.cpp:11
prnstream & endl(prnstream &)
virtual void curv_scale(const dvector &d, const dvector &x, const int &ii)
Definition: model21.cpp:184
virtual void restore_value(const ifstream &ifs)
Definition: model21.cpp:269
Description not yet available.
Definition: fvar.hpp:3398
virtual void copy_value_to_vector(const dvector &x, const int &ii)
Definition: model21.cpp:72
Description not yet available.
virtual void save_value(ofstream &ofs)
Definition: model21.cpp:46
Description not yet available.
Definition: fvar.hpp:4197
virtual void hess_scale(const dvector &d, const dvector &x, const int &ii)
Definition: model21.cpp:207
void allocate(int _phase_start)
Definition: model.cpp:117
virtual const char * label(void)
Definition: model21.cpp:27
istream & operator>>(const istream &input, const d3_array &arr3)
Read values from input stream into arr3.
Definition: d3_io.cpp:60
int rowmax(void) const
Definition: fvar.hpp:4295
Description not yet available.
Definition: admodel.h:312
void allocate(void)
Does not allocte, but initialize class members.
Definition: f3arr17.cpp:18
double initial_value
Definition: admodel.h:823
virtual void get_jacobian(const dvector &, const dvector &, const int &)
Definition: model21.cpp:18
unsigned int size_count(const dvector &x)
Returns total size of elements in vector x.
Definition: dsize.cpp:17
Stores integer.
Definition: fvar.hpp:7654
static cifstream * global_parfile
Definition: fvar.hpp:8857
int indexmin() const
Definition: fvar.hpp:4272
int rowmin(void) const
Definition: fvar.hpp:4291
Fundamental data type for reverse mode automatic differentiation.
Definition: fvar.hpp:1518
Description not yet available.
Definition: admodel.h:150