systemmodel.cpp
Go to the documentation of this file.
1 // $Id$
2 // Copyright (C) 2002 Klaas Gadeyne <first dot last at gmail dot com>
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU Lesser General Public License as published by
6 // the Free Software Foundation; either version 2.1 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 //
18 #include "systemmodel.h"
19 
20 // Constructor
21 template<typename T> SystemModel<T>::SystemModel(ConditionalPdf<T,T>* systempdf)
22 {
23 #ifdef __CONSTRUCTOR__
24  cout << "SystemModel::Constructor" << endl;
25 #endif // __CONSTRUCTOR__
26  if (systempdf != NULL)
27  {
28  switch(systempdf->NumConditionalArgumentsGet())
29  {
30  case 1:
31  {
32  _systemWithoutInputs = true;
33  _SystemPdf = systempdf;
34  break;
35  }
36  case 2:
37  {
38  _systemWithoutInputs = false;
39  _SystemPdf = systempdf;
40  break;
41  }
42  default:
43  {
44  cerr << "SystemModel::Constructor : SystemPdf can only have 1 or 2 conditional Arguments (x and u, in that order!))" << endl;
45  exit(-BFL_ERRMISUSE);
46  }
47  }
48  }
49 }
50 
51 // Destructor
52 template<typename T>
54 {
55 #ifdef __DESTRUCTOR__
56  cout << "SystemModel::Destructor" << endl;
57 #endif // __DESTRUCTOR__
58  /* KG: Probably a memory leak
59  Who should clean this up? Sometimes the user will have created
60  this Pdf, sometimes not (eg. by copy constructor). If we allways
61  delete it here.
62  There has to be a cleaner way to implement this!
63  */
64  // delete SystemPdf;
65 }
66 
67 // Copy constructor
68 /*
69 template<typename T>
70 SystemModel<T>::SystemModel(const SystemModel<T>& model)
71 {
72  SystemPdf = &(model.SystemPdfGet());
73 }
74 */
75 
76 // Get State Size
77 template<typename T> int
79 {
80  return _SystemPdf->DimensionGet();
81 }
82 
83 template<typename T> bool
85 {
86  return _systemWithoutInputs;
87 }
88 
89 // Get SystemPdf
90 template<typename T> ConditionalPdf<T,T>*
92 {
93  return _SystemPdf;
94 }
95 
96 // Set SystemPdf
97 template<typename T> void
99 {
100  assert(pdf != NULL);
101  switch(pdf->NumConditionalArgumentsGet())
102  {
103  case 1:
104  {
105  _systemWithoutInputs = true;
106  _SystemPdf = pdf;
107  break;
108  }
109  case 2:
110  {
111  _systemWithoutInputs = false;
112  _SystemPdf = pdf;
113  break;
114  }
115  default:
116  {
117  cerr << "SystemModel::SystemPdfSet() : SystemPdf can only have 1 or 2 conditional Arguments (x and u, in that order!))" << endl;
118  exit(-BFL_ERRMISUSE);
119  }
120  }
121 }
122 
123 // Simulate from the system model
124 template<typename T> T
125 SystemModel<T>::Simulate (const T& x, const T& u, int sampling_method,
126  void * sampling_args)
127 {
128  assert(_systemWithoutInputs == false);
129  _SystemPdf->ConditionalArgumentSet(0,x);
130  _SystemPdf->ConditionalArgumentSet(1,u);
131  Sample<T> Simulated(StateSizeGet());
132  _SystemPdf->SampleFrom(Simulated, sampling_method,sampling_args);
133  T result = Simulated.ValueGet();
134  return result;
135 }
136 
137 template<typename T> T
138 SystemModel<T>::Simulate (const T& x, int sampling_method,
139  void * sampling_args)
140 {
141  assert(_systemWithoutInputs == true);
142  _SystemPdf->ConditionalArgumentSet(0,x);
143  Sample<T> Simulated(StateSizeGet());
144  _SystemPdf->SampleFrom(Simulated, sampling_method,sampling_args);
145  T result = Simulated.ValueGet();
146  return result;
147 }
148 
149 template <typename T> Probability
150 SystemModel<T>::ProbabilityGet (const T& x_k, const T& x_kminusone,
151  const T& u)
152 {
153  assert(_systemWithoutInputs == false);
154  _SystemPdf->ConditionalArgumentSet(0,x_kminusone);
155  _SystemPdf->ConditionalArgumentSet(1,u);
156  return _SystemPdf->ProbabilityGet(x_k);
157 }
158 
159 template <typename T> Probability
160 SystemModel<T>::ProbabilityGet (const T& x_k, const T& x_kminusone)
161 {
162  assert(_systemWithoutInputs == true);
163  _SystemPdf->ConditionalArgumentSet(0,x_kminusone);
164  return _SystemPdf->ProbabilityGet(x_k);
165 }
#define BFL_ERRMISUSE
T & ValueGet()
Get the value of the Sample.
Class representing a probability (a double between 0 and 1)
Definition: bfl_constants.h:39
unsigned int NumConditionalArgumentsGet() const
Get the Number of conditional arguments.


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 Mon Feb 28 2022 21:56:33