ADMB Documentation  11.5.3197
 All Classes Files Functions Variables Typedefs Friends Defines
param_init_bounded_number_matrix.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id$
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  */
00007 #include "param_init_bounded_number_matrix.h"
00008 #include "admb_messages.h"
00009 #ifndef OPT_LIB
00010   #include <cassert>
00011 #endif
00012 
00013 param_init_bounded_number_matrix::param_init_bounded_number_matrix(): v(NULL),
00014   index_min(0), index_max(0)
00015 {
00016 }
00017 void param_init_bounded_number_matrix::allocate(int rowmin, int rowmax,
00018   int colmin, int colmax,
00019   const dmatrix& bmin, const dmatrix& bmax,
00020   const char* s)
00021 {
00022   imatrix phase_start(rowmin, rowmax, colmin, colmax);
00023   phase_start = 1;
00024   allocate(rowmin, rowmax, colmin, colmax, bmin, bmax, phase_start, s);
00025 }
00026 void param_init_bounded_number_matrix::allocate(int rowmin, int rowmax,
00027   int colmin, int colmax,
00028   const dmatrix& bmin, const dmatrix& bmax,
00029   const imatrix& phase_start,
00030   const char* s)
00031 {
00032 #ifndef OPT_LIB
00033   assert(v == NULL);
00034 #endif
00035 
00036   int size  = rowmax - rowmin + 1;
00037   if (size > 0)
00038   {
00039     index_min = rowmin;
00040     index_max = rowmax;
00041     v = new param_init_bounded_number_vector[size];
00042     if (!v)
00043     {
00044       cerr << " error trying to allocate memory in "
00045                "param_init_bounded_number_vector " << endl;
00046       ad_exit(1);
00047     }
00048     v -= index_min;
00049 
00050     for (int i = index_min; i <= index_max; i++)
00051     {
00052       /*if (it) v[i].set_initial_value(it[i]);*/
00053       adstring a = s + adstring("[") + str(i) + adstring("]");
00054       v[i].allocate(colmin, colmax, bmin[i], bmax[i], phase_start[i],
00055        (char*)(a));
00056     }
00057   }
00058 }
00059 void param_init_bounded_number_matrix::set_scalefactor(const double scalefactor)
00060 {
00061   for (int i = index_min; i <= index_max; i++)
00062   {
00063     v[i].set_scalefactor(scalefactor);
00064   }
00065 }
00066 void param_init_bounded_number_matrix::set_scalefactor(
00067   const dmatrix& scalefactor)
00068 {
00069   for (int i = index_min; i <= index_max; i++)
00070   {
00071     const dvector& dv = scalefactor(i);
00072     v[i].set_scalefactor(dv);
00073   }
00074 }
00075 dmatrix param_init_bounded_number_matrix::get_scalefactor() const
00076 {
00077   dmatrix scalefactor;
00078   if (index_min < index_max)
00079   {
00080     scalefactor.allocate(index_min, index_max);
00081     for (int i = index_min; i <= index_max; i++)
00082     {
00083       param_init_bounded_number_vector& pibv = v[i];
00084       dvector dv = pibv.get_scalefactor();
00085       int indexmin = pibv.indexmin();
00086       int indexmax = pibv.indexmax();
00087       scalefactor.allocate(indexmin, indexmax);
00088       scalefactor(i) = dv;
00089     }
00090   }
00091   return scalefactor;
00092 }
00093 void param_init_bounded_number_matrix::deallocate()
00094 {
00095   if (v)
00096   {
00097     for (int i = index_min; i <= index_max; i++)
00098     {
00099       v[i].deallocate();
00100     }
00101     v += index_min;
00102     delete [] v;
00103     v = NULL;
00104   }
00105 }
00106 param_init_bounded_number_vector& param_init_bounded_number_matrix::operator[](
00107   const int i) const
00108 {
00109 #ifndef OPT_LIB
00110   if (i < index_min)
00111   {
00112     ADMB_ARRAY_BOUNDS_ERROR("Index too low",
00113     "param_init_bounded_number_matrix::operator[](const int i) const",
00114     index_min, index_max, i);
00115   }
00116   if (i > index_max)
00117   {
00118     ADMB_ARRAY_BOUNDS_ERROR("Index too high",
00119     "param_init_bounded_number_matrix::operator[](const int i) const",
00120     index_min, index_max, i);
00121   }
00122 #endif
00123   return v[i];
00124 }
00125 param_init_bounded_number_vector& param_init_bounded_number_matrix::operator()(
00126   const int i) const
00127 {
00128 #ifndef OPT_LIB
00129   if (i < index_min)
00130   {
00131     ADMB_ARRAY_BOUNDS_ERROR("Index too low",
00132     "param_init_bounded_number_matrix::operator[](const int i) const",
00133     index_min, index_max, i);
00134   }
00135   if (i > index_max)
00136   {
00137     ADMB_ARRAY_BOUNDS_ERROR("Index too high",
00138     "param_init_bounded_number_matrix::operator[](const int i) const",
00139     index_min, index_max, i);
00140   }
00141 #endif
00142   return v[i];
00143 }
00144 param_init_bounded_number& param_init_bounded_number_matrix::operator()(
00145   const int i, const int j) const
00146 {
00147   return this->operator()(i)(j);
00148 }