YARP
Yet Another Robot Platform
arbitrator.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 
6 #ifndef YARP_MANAGER_ARBITRATOR
7 #define YARP_MANAGER_ARBITRATOR
8 
9 #include <map>
10 #include <vector>
11 
12 #include <yarp/manager/ymm-types.h>
13 #include <yarp/manager/node.h>
14 #include <yarp/manager/utility.h>
15 
16 
17 namespace yarp {
18 namespace manager {
19 
20 
25 class Arbitrator {
26 public:
27  Arbitrator() = default;
28  Arbitrator(const char* szPort) : strPort(szPort) {}
29  ~Arbitrator() = default;
30 
31  void setPort(const char* szPort) { if(szPort) { strPort = szPort; } }
32 
33  const char* getPort() { return strPort.c_str(); }
34 
35  const char* getRule(const char* con)
36  {
37  if(con && (rules.find(con) != rules.end())) {
38  return rules[con].c_str();
39  }
40  return nullptr;
41  }
42 
43  std::map<std::string, std::string>& getRuleMap() { return rules; }
44  int ruleCount() { return rules.size(); }
45 
46  GraphicModel* getModel() { return model;}
47  void setModel(GraphicModel* mdl) { model = mdl; };
48 
49  // modelBased is used to keep the graphic and geometric
50  // information which is directly loaded from application
51  // description file.
52  GraphicModel& getModelBase() { return modelBase;}
53  void setModelBase(GraphicModel& mdl) { modelBase = mdl; };
54 
55  void setOwner(Node* owner){ appOwner = owner; }
56  Node* owner() { return appOwner; }
57 
58  bool operator==(const Arbitrator& alt) const {
59  return (strPort == alt.strPort);
60  }
61 
62  std::map<std::string, double>& getAlphas( const char* con) {
63  return alphas[con];
64  }
65 
66  double getBias(const char* con) {
67  return biases[con];
68  }
69 
70  void addRule(const char* con, const char* rule);
71  void removeRule(const char* con);
72  bool trainWeights(const char* opnd);
73  bool trainWeights();
74  bool validate();
75 
76 protected:
77 
78 private:
79  std::string strPort;
80  std::map<std::string, std::string> rules;
81  GraphicModel* model {nullptr};
82  GraphicModel modelBase;
83  Node* appOwner {nullptr};
84 
85  std::map<std::string, std::map<std::string, double> > alphas;
86  std::map<std::string, double> biases;
87 
88 };
89 
90 
91 typedef std::vector<Arbitrator> ArbContainer;
92 typedef std::vector<Arbitrator>::iterator ArbIterator;
93 
94 } // namespace yarp
95 } // namespace manager
96 
97 
98 #endif // __YARP_MANAGER_ARBITRATOR__
Class port Arbitrator.
Definition: arbitrator.h:25
void setOwner(Node *owner)
Definition: arbitrator.h:55
void addRule(const char *con, const char *rule)
Class Arbitrator.
Definition: arbitrator.cpp:29
bool operator==(const Arbitrator &alt) const
Definition: arbitrator.h:58
double getBias(const char *con)
Definition: arbitrator.h:66
Arbitrator(const char *szPort)
Definition: arbitrator.h:28
GraphicModel * getModel()
Definition: arbitrator.h:46
GraphicModel & getModelBase()
Definition: arbitrator.h:52
std::map< std::string, double > & getAlphas(const char *con)
Definition: arbitrator.h:62
void setModel(GraphicModel *mdl)
Definition: arbitrator.h:47
void setModelBase(GraphicModel &mdl)
Definition: arbitrator.h:53
const char * getRule(const char *con)
Definition: arbitrator.h:35
void removeRule(const char *con)
Definition: arbitrator.cpp:40
void setPort(const char *szPort)
Definition: arbitrator.h:31
const char * getPort()
Definition: arbitrator.h:33
std::map< std::string, std::string > & getRuleMap()
Definition: arbitrator.h:43
a Node of a Graph
Definition: node.h:65
std::vector< Arbitrator > ArbContainer
Definition: arbitrator.h:91
std::vector< Arbitrator >::iterator ArbIterator
Definition: arbitrator.h:92
The main, catch-all namespace for YARP.
Definition: dirs.h:16