MC++
polymodel.hpp
1 // Copyright (C) 2014 Benoit Chachuat, Imperial College London.
2 // All Rights Reserved.
3 // This code is published under the Eclipse Public License.
4 
5 #ifndef MC__POLYMODEL_H
6 #define MC__POLYMODEL_H
7 
8 #include <iostream>
9 #include <iomanip>
10 #include <typeinfo>
11 #include <sstream>
12 #include <string>
13 #include <stdarg.h>
14 #include <cassert>
15 #include <climits>
16 #include <limits>
17 #include <stdlib.h>
18 #include <complex>
19 
20 #include "mcfunc.hpp"
21 #include "mcop.hpp"
22 
23 #undef MC__POLYMODEL_DEBUG
24 #define MC__POLYMODEL_CHECK
25 
26 namespace mc
27 {
28 
29 typedef unsigned long long poly_size;
30 
36 class PolyModel
38 {
39 public:
40 
44  PolyModel
46  ( const unsigned int nvar, const unsigned int nord )
47  { _size( nvar, nord ); }
49 
50  virtual ~PolyModel
51  ()
52  { _cleanup(); }
53 
55  unsigned int nvar
56  ()
57  const
58  { return _nvar; };
59 
61  unsigned int nord
62  ()
63  const
64  { return _nord; };
65 
67  unsigned int nmon
68  ()
69  const
70  { return _nmon; };
71 
73  const unsigned int* expmon
74  ()
75  const
76  { return _expmon; };
77 
79  unsigned int loc_expmon
80  ( const unsigned int *iexp )
81  const
82  { return _loc_expmon( iexp ); }
83 
85  const unsigned int* posord
86  ()
87  const
88  { return _posord; }
89 
91  poly_size get_binom
92  ( const unsigned int n, const unsigned int k )
93  const
94  { return _get_binom( n, k ); }
95 
97  class Exceptions
98  {
99  public:
101  enum TYPE{
102  SIZE=1,
104  UNDEF=-33
105  };
107  Exceptions( TYPE ierr ) : _ierr( ierr ){}
109  int ierr(){ return _ierr; }
111  std::string what(){
112  switch( _ierr ){
113  case SIZE:
114  return "mc::PolyModel\t Inconsistent polynomial model dimension";
115  case MAXSIZE:
116  return "mc::PolyModel\t Maximum size in polynomial model reached";
117  case UNDEF:
118  return "mc::PolyModel\t Feature not yet implemented in mc::PolyModel class";
119  default:
120  return "mc::PolyModel\t Undocumented error";
121  }
122  }
123 
124  private:
125  TYPE _ierr;
126  };
129 private:
131  void _size
132  ( const unsigned int nvar, const unsigned int nord );
133 
135  void _cleanup();
136 
137 protected:
139  unsigned int _nord;
140 
142  unsigned int _nvar;
143 
145  unsigned int _nmon;
146 
148  unsigned int *_posord;
149 
151  unsigned _posord_size;
152 
154  unsigned int *_expmon;
155 
157  unsigned _expmon_size;
158 
160  poly_size *_binom;
161 
163  std::pair<unsigned int, unsigned int> _binom_size;
164 
166  bool _modvar;
167 
169  void _set_bndmon();
170 
172  void _set_posord
173  ( const unsigned int nord );
174 
176  void _ext_posord
177  ( const unsigned int maxord );
178 
180  void _set_expmon
181  ( const unsigned int nord );
182 
184  void _ext_expmon
185  ( const unsigned int maxord, const bool full=false );
186 
188  void _next_expmon
189  ( unsigned int *iexp, const unsigned int iord ) const;
190 
192  unsigned int _loc_expmon
193  ( const unsigned int *iexp ) const;
194 
196  void _set_binom
197  ( const unsigned int nord );
198 
200  void _ext_binom
201  ( const unsigned int nord );
202 
204  poly_size _get_binom
205  ( const unsigned int n, const unsigned int k ) const;
206 };
207 
209 
210 inline void
211 PolyModel::_size
212 ( const unsigned int nvar, const unsigned int nord )
213 {
214  if( !nvar ) throw Exceptions( Exceptions::SIZE );
215 
216  _nvar = nvar;
217  _nord = nord;
218  _binom = new poly_size[nord?(nvar+nord-1)*(nord+1):nvar];
219  _binom_size = std::make_pair( nvar+nord-1, nord+1 );
220  _set_binom( nord );
221  _posord = new unsigned int[nord+2];
222  _posord_size = nord;
223  _set_posord( nord );
224  _nmon = _posord[_nord+1];
225  _expmon = new unsigned int[_nmon*nvar];
227  _set_expmon( nord );
228  _modvar = true;
229 }
230 
231 inline void
233 ( const unsigned int nord )
234 {
235  _posord[0] = 0;
236  _posord[1] = 1;
237  for( unsigned int i=1; i<=nord; i++ ){
238  poly_size _posord_next = _posord[i] + _get_binom( _nvar+i-1, i );
239  if( _posord_next > UINT_MAX )
241  _posord[i+1] = _posord_next;
242  }
243 
244 #ifdef MC__POLYMODEL_DEBUG
245  mc::display( 1, nord+2, _posord, 1, "_posord", std::cout );
246 #endif
247 }
248 
249 inline void
251 ( const unsigned int maxord )
252 {
253  if( maxord < _posord_size ) return;
254  delete[] _posord;
255  _posord = new unsigned int[maxord+2];
256  _posord_size = maxord;
257  _set_posord( maxord );
258 }
259 
260 inline void
262 ( const unsigned int nord )
263 {
264  unsigned int *iexp = new unsigned int[_nvar] ;
265  for( unsigned int k=0; k<_nvar; k++ ) _expmon[k] = 0;
266  for( unsigned int i=1; i<=nord; i++ ){
267  for( unsigned int j=0; j<_nvar; j++ ) iexp[j] = 0;
268  for( unsigned int j=_posord[i]; j<_posord[i+1]; j++ ){
269  _next_expmon( iexp, i );
270  for( unsigned int k=0; k<_nvar; k++ )
271  _expmon[j*_nvar+k] = iexp[k];
272  }
273  }
274  delete[] iexp;
275 
276 #ifdef MC__POLYMODEL_DEBUG
277  mc::display( _nvar, _expmon_size, _expmon, _nvar, "_expmon", std::cout );
278 #endif
279 }
280 
281 inline void
283 ( unsigned int *iexp, const unsigned int iord ) const
284 {
285  unsigned int curord;
286  do{
287  iexp[_nvar-1] += iord;
288  unsigned int j = _nvar;
289  while( j > 0 && iexp[j-1] > iord ){
290  iexp[j-1] -= iord + 1;
291  j-- ;
292  iexp[j-1]++;
293  }
294  curord = 0;
295  for( unsigned int i=0; i<_nvar; i++ ) curord += iexp[i];
296  } while( curord != iord );
297 }
298 
299 inline void
301 ( const unsigned int maxord, const bool full )
302 {
303  _ext_binom( maxord );
304  _ext_posord( maxord );
305  delete[] _expmon;
306  if( full ) _expmon_size = std::pow(maxord+1,_nvar);
307  else _expmon_size = _posord[maxord+1];
308  _expmon = new unsigned int[ _expmon_size*_nvar];
309  _set_expmon( maxord );
310  if( !full ) return;
311 
312  unsigned int *iexp = new unsigned int[_nvar];
313  for( unsigned int iord=maxord+1, jmon=_posord[maxord+1];
314  jmon<_expmon_size; iord++ ){
315  _ext_binom( iord );
316  _ext_posord( iord );
317  if( _posord[iord] >= _posord[iord+1] )
319  for( unsigned int ivar=0; ivar<_nvar; ivar++ ) iexp[ivar] = 0;
320  for( unsigned int kmon=_posord[iord]; kmon<_posord[iord+1]; kmon++ ){
321  _next_expmon( iexp, iord );
322  bool lt_maxord = true;
323  for( unsigned int ivar=0; ivar<_nvar; ivar++ ){
324  if( iexp[ivar] > maxord ){ lt_maxord = false; break; }
325  _expmon[jmon*_nvar+ivar] = iexp[ivar];
326  }
327  if( lt_maxord ){
328 #ifdef MC__POLYMODEL_DEBUG
329  std::cout << jmon << ":";
330  for( unsigned int ivar=0; ivar<_nvar; ivar++ )
331  std::cout << " " << _expmon[jmon*_nvar+ivar];
332  std::cout << std::endl;
333 #endif
334  jmon++;
335  if( jmon >= _expmon_size ) break;
336  }
337  }
338  }
339  delete[] iexp;
340  return;
341 }
342 
343 inline unsigned int
345 ( const unsigned int *iexp ) const
346 {
347  unsigned int ord = 0;
348  for( unsigned int i=0; i<_nvar; i++ ) ord += iexp[i];
349 #ifdef MC__POLYMODEL_CHECK
350  assert( ord<_nord+2 );
351 #endif
352  unsigned int pos = _posord[ord];
353 
354  unsigned int p = _nvar ;
355  for( unsigned int i=0; i<_nvar-1; i++ ){
356  p--;
357  for( unsigned int j=0; j<iexp[i]; j++ )
358  pos += _get_binom( p-1+ord-j, ord-j );
359  ord -= iexp[i];
360  }
361 
362  return pos;
363 }
364 
365 inline void
367 ( const unsigned int nord )
368 {
369  poly_size *p;
370  unsigned int k;
371  for( unsigned int i=0; i<_nvar+nord-1; i++ ){
372  p = &_binom[i*(nord+1)];
373  *p = 1;
374  p++;
375  *p = i+1;
376  p++;
377  k = ( i+1<nord? i+1: nord );
378  for( unsigned int j=2; j<=k; j++, p++ ) *p = *(p-1) * (i+2-j)/j;
379  for( unsigned int j=k+1; j<=nord; j++, p++ ) *p = 0.;
380  }
381 #ifdef MC__POLYMODEL_DEBUG
382  std::cout << "nvar: " << _nvar << " nord: " << nord << std::endl;
383  mc::display( _binom_size.second, _binom_size.first, _binom,
384  _binom_size.second, "_binom", std::cout );
385 #endif
386 }
387 
388 inline void
390 ( const unsigned int maxord )
391 {
392  if( maxord < _binom_size.second ) return;
393  delete[] _binom;
394  _binom = new poly_size[(_nvar+maxord-1)*(maxord+1)];
395  _binom_size = std::make_pair( _nvar+maxord-1, maxord+1 );
396  _set_binom( maxord );
397 }
398 
399 inline poly_size
401 ( const unsigned int n, const unsigned int k ) const
402 {
403 #ifdef MC__POLYMODEL_CHECK
404  assert( n<=_binom_size.first );
405  assert( k<=_binom_size.second );
406  assert( k<=n );
407 #endif
408  return( n? _binom[(n-1)*_binom_size.second+k]: 1 );
409 }
410 
411 inline void
412 PolyModel::_cleanup()
413 {
414  delete[] _expmon;
415  delete[] _posord;
416  delete[] _binom;
417 }
418 
424 template <typename T>
425 class PolyVar
427 {
428 
429 protected:
432 
434  double* _coefmon;
435 
437  mutable T* _bndord;
438 
440  mutable bool _bndord_uptd;
441 
444 
446  mutable T* _bndpol;
447 
448 public:
450  unsigned int nord
451  ()
452  const
453  { return( _PM? _PM->nord(): 0 ); };
454 
456  unsigned int nvar
457  ()
458  const
459  { return( _PM? _PM->nvar(): 0 ); };
460 
462  unsigned int nmon
463  ()
464  const
465  { return( _PM? _PM->nmon(): 1 ); };
466 
467 protected:
469  unsigned int _posord
470  ( const unsigned int iord )
471  const
472  { return _PM->posord()[iord]; };
473 
475  const unsigned int* _expmon
476  ( const unsigned int imon )
477  const
478  { return _PM->expmon()+imon*nvar(); };
479 
481  const unsigned int _loc_expmon
482  ( const unsigned int* iexp )
483  const
484  { return _PM->loc_expmon( iexp ); };
485 
487  poly_size _get_binom
488  ( const unsigned int n, const unsigned int k )
489  const
490  { return _PM->get_binom( n, k ); }
491 
493  void _size
494  ( PolyModel* env );
495 
497  void _resize
498  ( PolyModel* env );
499 
501  void _cleanup
502  ();
503 
506  ( const PolyVar<T>&var );
507 
509  virtual void _center();
510 
512  virtual void _set_bndpol
513  ( const T&bndpol );
514 
516  virtual void _set_bndpol
517  ( const T*bndpol );
518 
520  virtual void _unset_bndpol
521  ();
522 
524  virtual T _polybound
525  ( const int type )
526  const
527  = 0;
528 
530  virtual T _polybound
531  ()
532  const
533  = 0;
534 
536  virtual void _update_bndord
537  () const
538  = 0;
539 
540 public:
544  PolyVar
546  ( PolyModel* env=0 )
547  { _size( env ); }
548 
550  PolyVar
551  ( const PolyVar<T>& var )
552  { _size( var._PM );
553  // Set variable not linked to any environment
554  if( !_PM ){
555  _coefmon[0] = var._coefmon[0];
556  _bndord[0] = var._bndord[0];
557  }
558  // Set variable linked to an environment
559  else{
560  for( unsigned int i=0; i<nmon(); i++ ) _coefmon[i] = var._coefmon[i];
561  for( unsigned int i=0; i<nord()+2; i++) _bndord[i] = var._bndord[i];
562  }
564  if( var._bndpol ) _bndpol = new T( *var._bndpol );
565  }
566 
568  virtual ~PolyVar()
569  { delete[] _coefmon; delete[] _bndord; delete _bndpol; }
570 
572  virtual PolyVar<T>& set
574  { _resize( env );
575  _unset_bndpol(); _bndord_uptd = false;
576  return *this; }
577  //{ _PM = env; return *this; }
578 
580  virtual PolyVar<T>& set
581  ( const double* coefmon )
582  { for( unsigned int imon=0; imon<(_PM?nmon():1); imon++ )
583  _coefmon[imon] = coefmon[imon];
584  _unset_bndpol(); _bndord_uptd = false;
585  return *this; }
586 
588  virtual PolyVar<T>& set
589  ( std::pair<unsigned int, const double*>& coefmon )
590  { for( unsigned int imon=0; imon<(_PM?nmon():1); imon++ )
591  _coefmon[imon] = ( imon<coefmon.first && coefmon.second?
592  coefmon.second[imon]: 0. );
593  _unset_bndpol(); _bndord_uptd = false;
594  return *this; }
595 
597  virtual PolyVar<T>& set
598  ( const T& bndrem )
599  { *_bndrem = bndrem;
600  return *this; }
601 
603  virtual PolyVar<T>& set
604  ( const PolyVar<T>& var, const bool reset=true );
605 
607  virtual PolyVar<T>& get
608  ( PolyVar<T>&var, const bool reset=false );
609 
611  virtual PolyModel* env() const
612  { return _PM; }
613 
615  virtual T bound
616  ( const int type ) const
617  { return _polybound(type) + *_bndrem; }
618 
620  T bound() const
621  { return bndpol() + *_bndrem; }
622 
624  T bndpol() const
625  { if( !_bndpol ) _bndpol = new T( _polybound() );
626  return *_bndpol; }
627 
629  T bndord
630  ( const unsigned int iord )
631  const
632  { if( !iord || (_PM && iord<=nord()) )
633  { if( !_bndord_uptd ) _update_bndord(); return _bndord[iord]; }
634  return 0.; }
635  //{ return ( !iord || (_PM && iord<=nord()) )? _bndord[iord]: 0.; }
636 
638  T remainder
639  ()
640  const
641  { return( *_bndrem ); }
642 
644  virtual T B
645  ( const int type )
646  const
647  { return bound( type ); }
648 
650  virtual T B
651  ()
652  const
653  { return bound(); }
654 
656  T R
657  ()
658  const
659  { return remainder(); }
660 
662  double coefmon
663  ( const unsigned int*iexp )
664  const;
665 
667  std::pair<unsigned int, const double*> coefmon
668  ()
669  const;
670 
672  std::pair<unsigned int, const unsigned int*> expmon
673  ()
674  const;
675 
677  virtual PolyVar<T>& operator=
678  ( const PolyVar<T>& );
680 };
681 
683 
684 template <typename T> inline PolyVar<T>&
686 ( const PolyVar<T>& var, const bool reset )
687 {
688  if( !_PM || ( var._PM && nvar() < var.nvar() ) ) return *this;
689 
690  // Reset monomial coefficients to 0
691  for( unsigned int imon=0; reset && imon<nmon(); imon++ ) _coefmon[imon] = 0.;
692  if( reset ) *_bndrem = 0.;
693 
694  // Copy monomial coefficients from var into *this
695  _coefmon[0] = var._coefmon[0];
696  if( !var._PM ){ *_bndrem = *var._bndrem; _bndord_uptd = false; return *this; }
697  unsigned int*iexp = new unsigned int[nvar()];
698  for( unsigned int jmon=1; jmon<var.nmon() && jmon<var._posord(nord()+1); jmon++ ){
699  for( unsigned int ivar=0; ivar<nvar(); ivar++ )
700  iexp[ivar] = ( ivar<var.nvar()? var._expmon(jmon)[ivar]: 0 );
701  _coefmon[_loc_expmon(iexp)] = var._coefmon[jmon];
702  }
703  delete[] iexp;
704  for( unsigned int iord=nord()+1; iord<=var.nord(); iord++ )
705  *_bndrem += var.bndord(iord);
706  *_bndrem += *var._bndrem;
707  _unset_bndpol();
708  _bndord_uptd = false;
709  return *this;
710 }
711 
712 template <typename T> inline PolyVar<T>&
714 ( PolyVar<T>& var, const bool reset )
715 {
716  if( !_PM ){
717  var._coefmon[0] = _coefmon[0];
718  // Reset monomial coefficients to 0
719  if( reset ) _coefmon[0] = 0.;
720  return *this;
721  }
722  if( !var._PM || nvar() < var.nvar() || nord() < var.nord() )
723  return *this;
724 
725  // Copy monomial coefficients from *this into var
726  unsigned int*iexp = new unsigned int[nvar()];
727  for( unsigned int jmon=0; jmon<(var._PM?var.nmon():1); jmon++ ){
728  for( unsigned int ivar=0; ivar<nvar(); ivar++ )
729  iexp[ivar] = (ivar<var.nvar()? var._expmon(jmon)[ivar]: 0);
730  var._coefmon[jmon] = _coefmon[_loc_expmon(iexp)];
731  // Reset monomial coefficients to 0
732  if( reset ) _coefmon[_loc_expmon(iexp)] = 0.;
733  }
734  delete[] iexp;
735  *var._bndrem = 0.;
736  var._unset_bndpol();
737  var._bndord_uptd = false;
738 
739  if( reset ){
740  _unset_bndpol();
741  _bndord_uptd = false;
742  }
743  return *this;
744 }
745 
746 template <typename T> inline void
748 ( PolyModel* env )
749 {
750  _PM = env;
751  if( !_PM ){
752  _coefmon = new double[1];
753  _bndord = new T[1];
754  _bndrem = _bndord;
755  }
756  else{
757  _coefmon = new double[nmon()];
758  _bndord = new T[nord()+2];
759  _bndrem = _bndord + nord()+1;
760  }
761  _bndord_uptd = false;
762  _bndpol = 0;
763  return;
764 }
765 
766 template <typename T> inline void
768 {
769  delete [] _coefmon; delete [] _bndord; delete _bndpol;
770  _coefmon = 0; _bndord = _bndrem = _bndpol = 0;
771 }
772 
773 template <typename T> inline void
775 ( PolyModel* env )
776 {
777  if( _PM == env ) return;
778  _cleanup();
779  _size( env );
780 }
781 
782 template <typename T> inline PolyVar<T>&
784 ( const PolyVar<T>&var )
785 {
786  return _set( var );
787 }
788 
789 template <typename T> inline PolyVar<T>&
791 ( const PolyVar<T>&var )
792 {
793  // Same PolyVar?
794  if( this == &var ) return *this;
795 
796  // Reinitialization needed?
797  _resize( var._PM );
798 
799  // Set variable not linked to any environment
800  if( !_PM ){
801  _coefmon[0] = var._coefmon[0];
802  *_bndrem = *var._bndrem;
803  }
804  // Set variable linked to an environment
805  else{
806  for( unsigned int i=0; i<nmon(); i++ ) _coefmon[i] = var._coefmon[i];
807  for( unsigned int i=0; i<nord()+1 && var._bndord_uptd; i++) _bndord[i] = var._bndord[i];
808  *_bndrem = *var._bndrem;
809  }
810  _bndord_uptd = var._bndord_uptd;
811  // Set polynomial bound
812  _set_bndpol( var._bndpol );
813 
814  return *this;
815 }
816 
817 template <typename T> inline void
819 ()
820 {
821  delete _bndpol;
822  _bndpol = 0;
823 }
824 
825 template <typename T> inline void
827 ( const T*bndpol )
828 {
829  if( !bndpol ){
830  if( _bndpol ) delete _bndpol;
831  _bndpol = 0;
832  }
833  else if( !_bndpol )
834  _bndpol = new T( *bndpol );
835  else
836  *_bndpol = *bndpol;
837 }
838 
839 template <typename T> inline void
841 ( const T&bndpol )
842 {
843  if( !_bndpol )
844  _bndpol = new T( bndpol );
845  else
846  *_bndpol = bndpol;
847 }
848 
849 template <typename T> inline void
851 {
852  const double remmid = Op<T>::mid(*_bndrem);
853  _coefmon[0] += remmid;
854  if( _PM ) _bndord[0] = _coefmon[0];
855  *_bndrem -= remmid;
856  if( _bndpol ) *_bndpol += remmid;
857 }
858 
859 template <typename T> inline double
861 ( const unsigned int*iexp )
862 const
863 {
864  if( !_PM ) return 0;
865  const unsigned int imon = _PM->loc_expmon( iexp );
866  return( imon<nmon()? _coefmon[imon]: 0. );
867 }
868 
869 template <typename T> inline std::pair<unsigned int, const double*>
871 const
872 {
873  return std::make_pair( (_PM?nmon():1), _coefmon );
874 }
875 
876 template <typename T> inline std::pair<unsigned int, const unsigned int*>
878 const
879 {
880  return std::make_pair( (_PM?nmon()*nvar():1), _PM->expmon );
881 }
882 
883 } // namespace mc
884 
885 #endif
virtual PolyModel * env() const
Get pointer to associated polynomial model environment.
Definition: polymodel.hpp:611
unsigned _posord_size
Order used to size _posord.
Definition: polymodel.hpp:151
bool _modvar
Have any of the model variables been modified?
Definition: polymodel.hpp:166
unsigned int nmon() const
Total number of monomial terms in polynomial model.
Definition: polymodel.hpp:463
const unsigned int * expmon() const
Const pointer to array of size nmon()*nvar() with variable exponents on each monomial term...
Definition: polymodel.hpp:74
unsigned int _nvar
Number of variables in polynomial model.
Definition: polymodel.hpp:142
C++ base class for the computation of polynomial models for factorable functions: Environment...
Definition: polymodel.hpp:36
void _size(PolyModel *env)
Initialize private/protected members of variable.
Definition: polymodel.hpp:748
unsigned int _nord
Order of polynomial model.
Definition: polymodel.hpp:139
std::pair< unsigned int, const double * > coefmon() const
Get pair of size of, and const pointer to, array of (possibly scaled) monomial coefficients in multiv...
Definition: polymodel.hpp:870
virtual void _update_bndord() const =0
Update private/protected members of variable after manipulation the coefficients (pure virtual) ...
void _set_bndmon()
Populate array _bndmon
virtual ~PolyVar()
Destructor of variable.
Definition: polymodel.hpp:568
virtual void _center()
Center remainder error term _bndrem
Definition: polymodel.hpp:850
T remainder() const
Return remainder term of variable.
Definition: polymodel.hpp:639
void _set_expmon(const unsigned int nord)
Populate array _expmon up to order nord
Definition: polymodel.hpp:262
unsigned int * _posord
Array of size _nord with indices of first monomial term of order iord=1,...,_nord in polynomial model...
Definition: polymodel.hpp:148
unsigned int nmon() const
Total number of monomial terms in polynomial model.
Definition: polymodel.hpp:68
T * _bndrem
Pointer to remainder bound of variable (possibly NULL if not computed)
Definition: polymodel.hpp:443
virtual T _polybound() const =0
Polynomial range bounder using specified bounder type (pure virtual)
std::string what()
Error description.
Definition: polymodel.hpp:111
void _ext_binom(const unsigned int nord)
Extend array _binom with binomial coefficients up to order nord
Definition: polymodel.hpp:390
PolyModel * _PM
Pointer to corresponding polynomial model environment.
Definition: polymodel.hpp:431
poly_size * _binom
Array of (_nvar+_nord-1)*(_nord+1) contining binomial coefficients.
Definition: polymodel.hpp:160
std::pair< unsigned int, const unsigned int * > expmon() const
Get pair of size of, and const pointer to, array of monomial exponents in multivariate polynomial of ...
Definition: polymodel.hpp:877
const unsigned int _loc_expmon(const unsigned int *iexp) const
Index of monomial term whose variable exponents are the same as those in array iexp (of size nvar()) ...
Definition: polymodel.hpp:482
T * _bndpol
Pointer to polynomial bound of variable.
Definition: polymodel.hpp:446
unsigned int _loc_expmon(const unsigned int *iexp) const
Get index of monomial term with variable exponents iexp in 1,...,_nmon
Definition: polymodel.hpp:345
poly_size _get_binom(const unsigned int n, const unsigned int k) const
Get binomial coefficient .
Definition: polymodel.hpp:488
unsigned int loc_expmon(const unsigned int *iexp) const
Index of monomial term whose variable exponents are the same as those in array iexp (of size nvar()) ...
Definition: polymodel.hpp:80
void _resize(PolyModel *env)
Reinitialize private/protected members of variable.
Definition: polymodel.hpp:775
Exceptions(TYPE ierr)
Constructor for error ierr
Definition: polymodel.hpp:107
std::pair< unsigned int, unsigned int > _binom_size
Maximum binomial coefficients in array _binom.
Definition: polymodel.hpp:163
Exceptions of mc::PolyModel.
Definition: polymodel.hpp:97
TYPE
Enumeration type for TModel exception handling.
Definition: polymodel.hpp:101
void _cleanup()
Clean up private/protected members of variable.
Definition: polymodel.hpp:767
poly_size _get_binom(const unsigned int n, const unsigned int k) const
Get binomial coefficient .
Definition: polymodel.hpp:401
Number of variable in polynomial model must be nonzero.
Definition: polymodel.hpp:102
unsigned int _posord(const unsigned int iord) const
Index of first monomial term of order iord in polynomial model.
Definition: polymodel.hpp:470
virtual T B() const
Shortcut to mc::PolyVar::bound.
Definition: polymodel.hpp:651
Feature not yet implemented in mc::PolyModel.
Definition: polymodel.hpp:104
virtual PolyVar< T > & set(PolyModel *env)
Set polynomial model environment in variable as env
Definition: polymodel.hpp:573
const unsigned int * _expmon(const unsigned int imon) const
Const pointer to array of size nvar of variable exponents in monomial term imon of polynomial model...
Definition: polymodel.hpp:476
void _ext_posord(const unsigned int maxord)
Extend array _posord up to maximum order maxord
Definition: polymodel.hpp:251
poly_size get_binom(const unsigned int n, const unsigned int k) const
Get binomial coefficient .
Definition: polymodel.hpp:92
int ierr()
Error flag.
Definition: polymodel.hpp:109
C++ base class for the computation of polynomial models for factorable functions: Variable...
Definition: polymodel.hpp:425
unsigned int * _expmon
Array of size _nmon*_nvar with variable exponents in monomial terms. The exponent for variable ivar i...
Definition: polymodel.hpp:154
T bndord(const unsigned int iord) const
Retreive bound on all terms with (total) order iord in polynomial model.
Definition: polymodel.hpp:630
T bndpol() const
Retreive bound on multivariate polynomial using default bounder.
Definition: polymodel.hpp:624
Maximum size of polynomial model reached (monomials indexed as unsigned int)
Definition: polymodel.hpp:103
unsigned int nvar() const
Number of variables in polynomial model.
Definition: polymodel.hpp:457
unsigned int nord() const
Order of polynomial model.
Definition: polymodel.hpp:451
virtual void _set_bndpol(const T &bndpol)
Set polynomial bound in variable as bndpol
Definition: polymodel.hpp:841
T R() const
Shortcut to mc::PolyVar::remainder.
Definition: polymodel.hpp:657
bool _bndord_uptd
Whether the bounds in bndord are up-to-date.
Definition: polymodel.hpp:440
unsigned int nord() const
Order of polynomial model environment.
Definition: polymodel.hpp:62
T bound() const
Retreive bound on variable using default bounder.
Definition: polymodel.hpp:620
unsigned int _nmon
Total number of monomial terms in polynomial model.
Definition: polymodel.hpp:145
PolyModel(const unsigned int nvar, const unsigned int nord)
Constructor of polynomial model environment for nvar variables and order nord
Definition: polymodel.hpp:46
PolyVar(PolyModel *env=0)
Constructor of variable linked to polynomial model environment env
Definition: polymodel.hpp:546
const unsigned int * posord() const
Array of size _nord with indices of first monomial term of order iord=1,...,_nord in polynomial model...
Definition: polymodel.hpp:86
virtual PolyVar< T > & get(PolyVar< T > &var, const bool reset=false)
Copy multivariate polynomial coefficients from current variable into variable var, possibly defined in another polynomial model environment with less variables or with a lower expansion order. Copied coefficients are reset to 0 in current Taylor variable if reset=true, otherwise they are left unmodified (default).
Definition: polymodel.hpp:714
double * _coefmon
Array of size _nmon with monomial coefficients of variable.
Definition: polymodel.hpp:434
virtual void _unset_bndpol()
Unset polynomial bound in variable.
Definition: polymodel.hpp:819
void _set_binom(const unsigned int nord)
Populate array _binom with binomial coefficients up to order nord
Definition: polymodel.hpp:367
T * _bndord
Array of size _nord+2 with bounds for all terms of degrees iord=0,...,_nord as well as the remainder ...
Definition: polymodel.hpp:437
void _next_expmon(unsigned int *iexp, const unsigned int iord) const
Generate variable exponents iexp for subsequent monomial order iord
Definition: polymodel.hpp:283
virtual ~PolyModel()
Destructor of polynomial model environment.
Definition: polymodel.hpp:51
unsigned int nvar() const
Number of variables in polynomial model environment.
Definition: polymodel.hpp:56
PolyVar< T > & _set(const PolyVar< T > &var)
Set variable equal to var
Definition: polymodel.hpp:791
void _set_posord(const unsigned int nord)
Populate array _posord up to order nord
Definition: polymodel.hpp:233
void _ext_expmon(const unsigned int maxord, const bool full=false)
Extend array _expmon up to order maxord to accomodate maxmon coefficients.
Definition: polymodel.hpp:301
unsigned _expmon_size
Number of monomial coefficients used to size _expmon.
Definition: polymodel.hpp:157
C++ structure to allow usage of various template parameters in the types mc::McCormick, mc::TModel, mc::TVar, and mc::SpecBnd of MC++ _ Specialization of this structure is required for the template parameters can be found in the header files defining the types mc::McCormick, mc::TModel, mc::TVar, and mc::SpecBnd.
Definition: mcop.hpp:13