ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
param_init_bounded_number_matrix.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  */
8 #include "admb_messages.h"
9 #ifndef OPT_LIB
10  #include <cassert>
11 #endif
12 
15  v(NULL),
16  index_min(0),
17  index_max(-1)
18 {
19 }
22 {
23  deallocate();
24 }
41  int rowmin, int rowmax,
42  int colmin, int colmax,
43  const dmatrix& bmin, const dmatrix& bmax,
44  const char* s)
45 {
46  imatrix phase_start(rowmin, rowmax, colmin, colmax);
47  phase_start = 1;
48  allocate(rowmin, rowmax, colmin, colmax, bmin, bmax, phase_start, s);
49 }
67  int rowmin, int rowmax,
68  int colmin, int colmax,
69  const dmatrix& bmin, const dmatrix& bmax,
70  const imatrix& phase_start,
71  const char* s)
72 {
73 #ifndef OPT_LIB
74  assert(v == NULL);
75 #endif
76 
77  if (rowmax >= rowmin)
78  {
79  unsigned int size = static_cast<unsigned int>(rowmax - rowmin + 1);
81  if (!v)
82  {
83  cerr << " error trying to allocate memory in "
84  "param_init_bounded_number_vector " << endl;
85  ad_exit(1);
86  }
87 
88  index_min = rowmin;
89  index_max = rowmax;
90  v -= index_min;
91 
92  for (int i = index_min; i <= index_max; ++i)
93  {
94  /*if (it) v[i].set_initial_value(it[i]);*/
95  adstring a = s + adstring("[") + str(i) + adstring("]");
96  v[i].allocate(colmin, colmax, bmin[i], bmax[i], phase_start[i],
97  (char*)(a));
98  }
99  }
100 }
107  const double scalefactor)
108 {
109 #ifndef OPT_LIB
110  assert(v != NULL);
111 #endif
112 
113  for (int i = index_min; i <= index_max; ++i)
114  {
115  v[i].set_scalefactor(scalefactor);
116  }
117 }
125  const dmatrix& scalefactor)
126 {
127 #ifndef OPT_LIB
128  assert(v != NULL);
129 #endif
130  for (int i = index_min; i <= index_max; i++)
131  {
132  v[i].set_scalefactor(scalefactor(i));
133  }
134 }
140 {
141  dmatrix scalefactor;
142  if (index_min < index_max)
143  {
144  scalefactor.allocate(index_min, index_max);
145  for (int i = index_min; i <= index_max; i++)
146  {
148  scalefactor(i).allocate(vi.indexmin(), vi .indexmax());
149  scalefactor(i) = vi.get_scalefactor();
150  }
151  }
152  return scalefactor;
153 }
158 {
159  if (v)
160  {
161  for (int i = index_min; i <= index_max; i++)
162  {
163  v[i].deallocate();
164  }
165  v += index_min;
166  delete [] v;
167  v = NULL;
168  }
169 }
178 {
179 #ifndef OPT_LIB
180  if (i < index_min)
181  {
182  ADMB_ARRAY_BOUNDS_ERROR("Index too low",
183  "param_init_bounded_number_matrix::operator[](const int i) const",
184  index_min, index_max, i);
185  }
186  if (i > index_max)
187  {
188  ADMB_ARRAY_BOUNDS_ERROR("Index too high",
189  "param_init_bounded_number_matrix::operator[](const int i) const",
190  index_min, index_max, i);
191  }
192 #endif
193  return v[i];
194 }
203 {
204 #ifndef OPT_LIB
205  if (i < index_min)
206  {
207  ADMB_ARRAY_BOUNDS_ERROR("Index too low",
208  "param_init_bounded_number_matrix::operator[](const int i) const",
209  index_min, index_max, i);
210  }
211  if (i > index_max)
212  {
213  ADMB_ARRAY_BOUNDS_ERROR("Index too high",
214  "param_init_bounded_number_matrix::operator[](const int i) const",
215  index_min, index_max, i);
216  }
217 #endif
218  return v[i];
219 }
228 param_init_bounded_number_matrix::operator()(const int i, const int j) const
229 {
230  return this->operator()(i)(j);
231 }
Description not yet available.
Definition: imatrix.h:69
void allocate(void)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: dmat0.cpp:8
param_init_bounded_number_vector & operator()(const int i) const
Returns param_init_bounded_vector for index i.
exitptr ad_exit
Definition: gradstrc.cpp:53
void set_scalefactor(const double scalefactor)
Set scalefactor for each element of param_init_bounded_number_matrix.
void deallocate()
Deallocate param_init_bounded_number_vector memory.
Definition: model48.cpp:46
void allocate(int rowmin, int rowmax, int colmin, int colmax, const dmatrix &bmin, const dmatrix &bmax, const char *s)
Allocate matrix of param_init_bounded numbers with dimension [rowmin to rowmax] x [colmin to colmax] ...
Description not yet available.
Definition: admodel.h:1228
prnstream & endl(prnstream &)
param_init_bounded_number_vector * v
Description not yet available.
Definition: fvar.hpp:2819
#define ADMB_ARRAY_BOUNDS_ERROR(message, function, lower_bounds, upper_bounds, index)
Definition: admb_messages.h:47
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
dmatrix get_scalefactor() const
Returns matrix with scalefactors for each element in param_init_bounded_number_matrix.
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
Class object for init_bounded_number vector.
Definition: admodel.h:2915
param_init_bounded_number_vector & operator[](const int i) const
Returns param_init_bounded_vector for index i.