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