xc
Action.h
1 // -*-c++-*-
2 //----------------------------------------------------------------------------
3 // xc utils library; general purpose classes and functions.
4 //
5 // Copyright (C) Luis C. Pérez Tato
6 //
7 // XC utils is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // This software is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program.
19 // If not, see <http://www.gnu.org/licenses/>.
20 //----------------------------------------------------------------------------
21 //Action.hxx
22 
23 #ifndef ACTION_H
24 #define ACTION_H
25 
26 #include <string>
27 #include <vector>
28 #include <deque>
29 #include <cmath>
30 #include "utility/kernel/NamedEntity.h"
31 #include "ActionRelationships.h"
32 
35 namespace cmb_acc{
36 
37 class ActionWrapperList;
38 
40 //
41 //
44 class Action: public NamedEntity
45  {
46  std::string description;
47  ActionRelationships relaciones;
48  bool nodet;
49  double f_pond;
50 
51  void clean_names(void);
52  bool incompatible(const Action &f) const;
53  void multiplica(const double &d);
54  void suma(const Action &f);
55  public:
56  static const double zero;
57  Action(const std::string &n="", const std::string &descrip="");
58 
59  static Action NULA(void);
61  inline void setName(const std::string &nmb)
62  { NamedEntity::Name()= nmb; }
63  const std::string getExpandedName(void) const;
65  inline const std::string &getDescription(void) const
66  { return description; }
68  inline void setDescription(const std::string &desc)
69  { description= desc; }
70  const ActionRelationships &getRelaciones(void) const
71  { return relaciones; }
72  inline double getWeightingFactor(void) const
73  { return f_pond; }
74  inline void setWeightingFactor(const double &f)
75  { f_pond= f; }
76 
77  inline bool notDeterminant(void) const
78  { return nodet; }
79  void setNotDeterminant(const bool &b)
80  { nodet= b; }
81 
82  typedef std::map<std::string,float> map_descomp;
83  map_descomp getComponents(void) const;
84  boost::python::dict getComponentsPy(void) const;
85  boost::python::dict getPyDict(void) const;
86  void setPyDict(const boost::python::dict &);
87 
88  bool Incompatible(const Action &) const;
91  inline bool Compatible(const Action &f) const
92  { return !Incompatible(f); }
93 
94  bool Simple(void) const;
96  inline bool Nula(const double &tol= zero) const
97  { return (fabs(f_pond)<tol); }
99  Action GetMult(const double &d) const
100  {
101  Action retval(*this);
102  retval*=(d);
103  return retval;
104  }
106  inline Action &operator*=(const double &d)
107  {
108  multiplica(d);
109  return *this;
110  }
112  inline Action &operator+=(const Action &f)
113  {
114  suma(f);
115  return *this;
116  }
118  inline friend Action operator*(const double &d,const Action &f)
119  { return f.GetMult(d); }
121  inline friend Action operator*(const Action &f,const double &d)
122  { return d*f; }
124  inline friend Action operator+(const Action &f1,const Action &f2)
125  {
126  Action retval(f1);
127  retval+=(f2);
128  return retval;
129  }
130 
131  std::vector<double> getCoefficients(const std::vector<std::string> &) const;
132  boost::python::list getCoefficientsPy(const boost::python::list &) const;
133  virtual void Print(std::ostream &os) const;
134  };
135 
136 std::ostream &operator<<(std::ostream &os,const Action &acc);
137 
138 bool incompatibles(const Action &acc_i,const Action &acc_j);
139 
141 template <class InputIterator>
142 std::string actionsNames(InputIterator begin,InputIterator end)
143  {
144  std::string retval;
145  InputIterator i=begin;
146  retval= (*i).getName(); i++;
147  for(;i!=end;i++)
148  retval+= "," + (*i).getName();
149  return retval;
150  }
151 
153 template <class InputIterator>
154 std::string actionPtrsNames(InputIterator begin,InputIterator end)
155  {
156  std::string retval;
157  InputIterator i=begin;
158  retval= (*i)->getName(); i++;
159  for(;i!=end;i++)
160  retval+= "," + (*i)->getName();
161  return retval;
162  }
163 } //fin namespace nmb_acc.
164 
165 #endif
map_descomp getComponents(void) const
When the actions is a combination return its decomposition.
Definition: Action.cc:68
bool Compatible(const Action &f) const
Return true if this actions is compatible with the argument one.
Definition: Action.h:91
boost::python::dict getPyDict(void) const
Return a Python dictionary with the object members values.
Definition: Action.cc:119
friend Action operator*(const Action &f, const double &d)
Product by a scalar.
Definition: Action.h:121
static const double zero
Treshold to consider the action as zero.
Definition: Action.h:56
void setName(const std::string &nmb)
Sets the name to the action.
Definition: Action.h:61
Routines to generate combinations of actions.
bool Incompatible(const Action &) const
Return true if this actions is not compatible with the argument one, so they cannot be present both i...
Definition: Action.cc:266
bool Simple(void) const
Return true if the action is not a combination of simpler ones.
Definition: Action.cc:50
std::string actionPtrsNames(InputIterator begin, InputIterator end)
Returns a list with the action names.
Definition: Action.h:154
void setPyDict(const boost::python::dict &)
Set the values of the object members from a Python dictionary.
Definition: Action.cc:130
bool incompatibles(const Action &acc_i, const Action &acc_j)
Return true if actions are incompatible.
Definition: Action.cc:285
Action & operator+=(const Action &f)
Addition.
Definition: Action.h:112
Action(const std::string &n="", const std::string &descrip="")
Default constructor.
Definition: Action.cc:37
std::string & Name(void)
Return a reference to the object name.
Definition: NamedEntity.h:52
boost::python::list getCoefficientsPy(const boost::python::list &) const
When it&#39;s a combination, it returns the factors that multiply each of the actions in the argument...
Definition: Action.cc:160
Action or linear combination of actions.
Definition: Action.h:44
Action & operator*=(const double &d)
Producto por un escalar.
Definition: Action.h:106
std::string actionsNames(InputIterator begin, InputIterator end)
Returns a list with the action names.
Definition: Action.h:142
const std::string & getDescription(void) const
Return the description of the action.
Definition: Action.h:65
boost::python::dict getComponentsPy(void) const
Return the action components in a Python dictionary.
Definition: Action.cc:105
virtual void Print(std::ostream &os) const
Print stuff.
Definition: Action.cc:278
static Action NULA(void)
Return una acción nula.
Definition: Action.cc:42
friend Action operator+(const Action &f1, const Action &f2)
Addition.
Definition: Action.h:124
const std::string getExpandedName(void) const
Return the expandend name by applying the distributive property of the multiplication so...
Definition: Action.cc:56
void setDescription(const std::string &desc)
Set the description of the action.
Definition: Action.h:68
Object identified by a name.
Definition: NamedEntity.h:37
std::vector< double > getCoefficients(const std::vector< std::string > &) const
When it&#39;s a combination, it returns the factors that multiply each of the actions in the argument...
Definition: Action.cc:143
Action GetMult(const double &d) const
Return la acción multiplicada por un escalar.
Definition: Action.h:99
Relationship of an action with the other ones.
Definition: ActionRelationships.h:37
friend Action operator*(const double &d, const Action &f)
Product by a scalar.
Definition: Action.h:118
bool Nula(const double &tol=zero) const
Return verdadero si la acción es nula.
Definition: Action.h:96