systemmodel.cpp
Go to the documentation of this file.
00001 // $Id: systemmodel.cpp 29495 2008-08-13 12:57:49Z tdelaet $
00002 // Copyright (C) 2002 Klaas Gadeyne <first dot last at gmail dot com>
00003 //
00004 // This program is free software; you can redistribute it and/or modify
00005 // it under the terms of the GNU Lesser General Public License as published by
00006 // the Free Software Foundation; either version 2.1 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU Lesser General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU Lesser General Public License
00015 // along with this program; if not, write to the Free Software
00016 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017 //
00018 #include "systemmodel.h"
00019 
00020 // Constructor
00021 template<typename T> SystemModel<T>::SystemModel(ConditionalPdf<T,T>* systempdf)
00022 {
00023 #ifdef __CONSTRUCTOR__
00024   cout << "SystemModel::Constructor" << endl;
00025 #endif // __CONSTRUCTOR__
00026   if (systempdf != NULL)
00027     {
00028       switch(systempdf->NumConditionalArgumentsGet())
00029         {
00030         case 1:
00031           {
00032             _systemWithoutInputs = true;
00033             _SystemPdf  = systempdf;
00034             break;
00035           }
00036         case 2:
00037           {
00038           _systemWithoutInputs = false;
00039           _SystemPdf  = systempdf;
00040           break;
00041           }
00042         default:
00043           {
00044             cerr << "SystemModel::Constructor : SystemPdf can only have 1 or 2 conditional Arguments (x and u, in that order!))" << endl;
00045             exit(-BFL_ERRMISUSE);
00046           }
00047         }
00048     }
00049 }
00050 
00051 // Destructor
00052 template<typename T>
00053 SystemModel<T>::~SystemModel()
00054 {
00055 #ifdef __DESTRUCTOR__
00056   cout << "SystemModel::Destructor" << endl;
00057 #endif // __DESTRUCTOR__
00058   /* KG: Probably a memory leak
00059      Who should clean this up? Sometimes the user will have created
00060      this Pdf, sometimes not (eg. by copy constructor).  If we allways
00061      delete it here.
00062      There has to be a cleaner way to implement this!
00063   */
00064   // delete SystemPdf;
00065 }
00066 
00067 // Copy constructor
00068 /*
00069 template<typename T>
00070 SystemModel<T>::SystemModel(const SystemModel<T>& model)
00071 {
00072   SystemPdf  = &(model.SystemPdfGet());
00073 }
00074 */
00075 
00076 // Get State Size
00077 template<typename T> int
00078 SystemModel<T>::StateSizeGet() const
00079 {
00080   return _SystemPdf->DimensionGet();
00081 }
00082 
00083 template<typename T> bool
00084 SystemModel<T>::SystemWithoutInputs() const
00085 {
00086   return _systemWithoutInputs;
00087 }
00088 
00089 // Get SystemPdf
00090 template<typename T> ConditionalPdf<T,T>*
00091 SystemModel<T>::SystemPdfGet()
00092 {
00093   return _SystemPdf;
00094 }
00095 
00096 // Set SystemPdf
00097 template<typename T> void
00098 SystemModel<T>::SystemPdfSet(ConditionalPdf<T,T>* pdf)
00099 {
00100   assert(pdf != NULL);
00101   switch(pdf->NumConditionalArgumentsGet())
00102     {
00103     case 1:
00104       {
00105         _systemWithoutInputs = true;
00106         _SystemPdf  = pdf;
00107         break;
00108       }
00109     case 2:
00110       {
00111         _systemWithoutInputs = false;
00112         _SystemPdf  = pdf;
00113         break;
00114       }
00115     default:
00116       {
00117         cerr << "SystemModel::SystemPdfSet() : SystemPdf can only have 1 or 2 conditional Arguments (x and u, in that order!))" << endl;
00118         exit(-BFL_ERRMISUSE);
00119       }
00120     }
00121 }
00122 
00123 // Simulate from the system model
00124 template<typename T> T
00125 SystemModel<T>::Simulate (const T& x, const T& u, int sampling_method,
00126                           void * sampling_args)
00127 {
00128   assert(_systemWithoutInputs == false);
00129   _SystemPdf->ConditionalArgumentSet(0,x);
00130   _SystemPdf->ConditionalArgumentSet(1,u);
00131   Sample<T> Simulated(StateSizeGet());
00132   _SystemPdf->SampleFrom(Simulated, sampling_method,sampling_args);
00133   T result = Simulated.ValueGet();
00134   return result;
00135 }
00136 
00137 template<typename T> T
00138 SystemModel<T>::Simulate (const T& x, int sampling_method,
00139                           void * sampling_args)
00140 {
00141   assert(_systemWithoutInputs == true);
00142   _SystemPdf->ConditionalArgumentSet(0,x);
00143   Sample<T> Simulated(StateSizeGet());
00144   _SystemPdf->SampleFrom(Simulated, sampling_method,sampling_args);
00145   T result = Simulated.ValueGet();
00146   return result;
00147 }
00148 
00149 template <typename T> Probability
00150 SystemModel<T>::ProbabilityGet (const T& x_k, const T& x_kminusone,
00151                                 const T& u)
00152 {
00153   assert(_systemWithoutInputs == false);
00154   _SystemPdf->ConditionalArgumentSet(0,x_kminusone);
00155   _SystemPdf->ConditionalArgumentSet(1,u);
00156   return _SystemPdf->ProbabilityGet(x_k);
00157 }
00158 
00159 template <typename T> Probability
00160 SystemModel<T>::ProbabilityGet (const T& x_k, const T& x_kminusone)
00161 {
00162   assert(_systemWithoutInputs == true);
00163   _SystemPdf->ConditionalArgumentSet(0,x_kminusone);
00164   return _SystemPdf->ProbabilityGet(x_k);
00165 }


bfl
Author(s): Klaas Gadeyne, Wim Meeussen, Tinne Delaet and many others. See web page for a full contributor list. ROS package maintained by Wim Meeussen.
autogenerated on Fri Aug 28 2015 10:10:21