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 ActionWrapper;
38 class ActionWrapperList;
39 class ActionsFamily;
40 
42 //
43 //
46 class Action: public NamedEntity
47  {
48  std::string description;
49  ActionRelationships relaciones;
50  bool nodet;
51  double f_pond;
52 
53  void clean_names(void);
54  bool incompatible(const Action &f) const;
55  void multiplica(const double &d);
56  void suma(const Action &f);
57  public:
58  static const double zero;
59  Action(const std::string &n="", const std::string &descrip="");
60 
61  static Action NULA(void);
63  inline void setName(const std::string &nmb)
64  { NamedEntity::Name()= nmb; }
65  const std::string getExpandedName(void) const;
67  inline const std::string &getDescription(void) const
68  { return description; }
70  inline void setDescription(const std::string &desc)
71  { description= desc; }
72  const ActionRelationships &getRelaciones(void) const
73  { return relaciones; }
74  inline double getWeightingFactor(void) const
75  { return f_pond; }
76  inline void setWeightingFactor(const double &f)
77  { f_pond= f; }
78 
79  inline bool notDeterminant(void) const
80  { return nodet; }
81  void setNotDeterminant(const bool &b)
82  { nodet= b; }
83 
84  typedef std::map<std::string,float> map_descomp;
85  map_descomp getComponents(void) const;
86  boost::python::dict getComponentsPy(void) const;
87  boost::python::dict getPyDict(void) const;
88  void setPyDict(const boost::python::dict &);
89 
90  bool Incompatible(const Action &) const;
93  inline bool Compatible(const Action &f) const
94  { return !Incompatible(f); }
95  bool Contains(const Action &f) const;
96  bool ContainsAnyOf(const ActionWrapper &) const;
97  bool ContainsAnyOf(const ActionWrapperList &) const;
98  bool ContainsAnyOf(const ActionsFamily &) const;
99 
100  bool Simple(void) const;
102  inline bool Nula(const double &tol= zero) const
103  { return (fabs(f_pond)<tol); }
105  Action GetMult(const double &d) const
106  {
107  Action retval(*this);
108  retval*=(d);
109  return retval;
110  }
112  inline Action &operator*=(const double &d)
113  {
114  multiplica(d);
115  return *this;
116  }
118  inline Action &operator+=(const Action &f)
119  {
120  suma(f);
121  return *this;
122  }
124  inline friend Action operator*(const double &d,const Action &f)
125  { return f.GetMult(d); }
127  inline friend Action operator*(const Action &f,const double &d)
128  { return d*f; }
130  inline friend Action operator+(const Action &f1,const Action &f2)
131  {
132  Action retval(f1);
133  retval+=(f2);
134  return retval;
135  }
136 
137  std::vector<double> getCoefficients(const std::vector<std::string> &) const;
138  boost::python::list getCoefficientsPy(const boost::python::list &) const;
139  virtual void Print(std::ostream &os) const;
140  };
141 
142 std::ostream &operator<<(std::ostream &os,const Action &acc);
143 
144 bool incompatibles(const Action &acc_i,const Action &acc_j);
145 
147 template <class InputIterator>
148 std::string actionsNames(InputIterator begin,InputIterator end)
149  {
150  std::string retval;
151  InputIterator i=begin;
152  retval= (*i).getName(); i++;
153  for(;i!=end;i++)
154  retval+= "," + (*i).getName();
155  return retval;
156  }
157 
159 template <class InputIterator>
160 std::string actionPtrsNames(InputIterator begin,InputIterator end)
161  {
162  std::string retval;
163  InputIterator i=begin;
164  retval= (*i)->getName(); i++;
165  for(;i!=end;i++)
166  retval+= "," + (*i)->getName();
167  return retval;
168  }
169 } //fin namespace nmb_acc.
170 
171 #endif
map_descomp getComponents(void) const
When the actions is a combination return its decomposition.
Definition: Action.cc:70
bool Compatible(const Action &f) const
Return true if this actions is compatible with the argument one.
Definition: Action.h:93
boost::python::dict getPyDict(void) const
Return a Python dictionary with the object members values.
Definition: Action.cc:121
friend Action operator*(const Action &f, const double &d)
Product by a scalar.
Definition: Action.h:127
static const double zero
Treshold to consider the action as zero.
Definition: Action.h:58
List of representative values of actions (ActionWrapper objects).
Definition: ActionWrapperList.h:42
void setName(const std::string &nmb)
Sets the name to the action.
Definition: Action.h:63
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:272
bool Simple(void) const
Return true if the action is not a combination of simpler ones.
Definition: Action.cc:52
std::string actionPtrsNames(InputIterator begin, InputIterator end)
Returns a list with the action names.
Definition: Action.h:160
void setPyDict(const boost::python::dict &)
Set the values of the object members from a Python dictionary.
Definition: Action.cc:132
bool incompatibles(const Action &acc_i, const Action &acc_j)
Return true if actions are incompatible.
Definition: Action.cc:355
Action & operator+=(const Action &f)
Addition.
Definition: Action.h:118
Action(const std::string &n="", const std::string &descrip="")
Default constructor.
Definition: Action.cc:39
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:162
Action or linear combination of actions.
Definition: Action.h:46
Action & operator*=(const double &d)
Producto por un escalar.
Definition: Action.h:112
std::string actionsNames(InputIterator begin, InputIterator end)
Returns a list with the action names.
Definition: Action.h:148
bool ContainsAnyOf(const ActionWrapper &) const
Return true if any of the given actions is found on this container.
Definition: Action.cc:309
const std::string & getDescription(void) const
Return the description of the action.
Definition: Action.h:67
boost::python::dict getComponentsPy(void) const
Return the action components in a Python dictionary.
Definition: Action.cc:107
virtual void Print(std::ostream &os) const
Print stuff.
Definition: Action.cc:348
static Action NULA(void)
Return una acción nula.
Definition: Action.cc:44
bool Contains(const Action &f) const
Return true if this actions contains the given one.
Definition: Action.cc:284
friend Action operator+(const Action &f1, const Action &f2)
Addition.
Definition: Action.h:130
const std::string getExpandedName(void) const
Return the expandend name by applying the distributive property of the multiplication so...
Definition: Action.cc:58
void setDescription(const std::string &desc)
Set the description of the action.
Definition: Action.h:70
Base class for action design values and action groups.
Definition: ActionWrapper.h:42
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:145
Action GetMult(const double &d) const
Return la acción multiplicada por un escalar.
Definition: Action.h:105
Relationship of an action with the other ones.
Definition: ActionRelationships.h:39
friend Action operator*(const double &d, const Action &f)
Product by a scalar.
Definition: Action.h:124
Family of actions (permanent, variable, accidental,...)
Definition: ActionsFamily.h:44
bool Nula(const double &tol=zero) const
Return verdadero si la acción es nula.
Definition: Action.h:102