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