YARP
Yet Another Robot Platform
arbitrator.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 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__
yarp::manager::Arbitrator::setOwner
void setOwner(Node *owner)
Definition: arbitrator.h:58
yarp::manager::Arbitrator::removeRule
void removeRule(const char *con)
Definition: arbitrator.cpp:44
yarp::manager::Arbitrator::validate
bool validate()
Definition: arbitrator.cpp:130
yarp::manager::Arbitrator
Class port Arbitrator.
Definition: arbitrator.h:28
yarp::manager::Arbitrator::setPort
void setPort(const char *szPort)
Definition: arbitrator.h:34
yarp::manager::Arbitrator::setModel
void setModel(GraphicModel *mdl)
Definition: arbitrator.h:50
yarp::manager::ArbContainer
std::vector< Arbitrator > ArbContainer
Definition: arbitrator.h:94
yarp::manager::Arbitrator::getModel
GraphicModel * getModel()
Definition: arbitrator.h:49
utility.h
yarp::manager::Arbitrator::Arbitrator
Arbitrator()=default
yarp::manager::Arbitrator::getPort
const char * getPort()
Definition: arbitrator.h:36
yarp::manager::ArbIterator
std::vector< Arbitrator >::iterator ArbIterator
Definition: arbitrator.h:95
yarp::manager::Arbitrator::getBias
double getBias(const char *con)
Definition: arbitrator.h:69
node.h
yarp::manager::Arbitrator::operator==
bool operator==(const Arbitrator &alt) const
Definition: arbitrator.h:61
yarp::manager::Arbitrator::~Arbitrator
~Arbitrator()=default
yarp::manager::Node
a Node of a Graph
Definition: node.h:68
ymm-types.h
yarp::manager::Arbitrator::getAlphas
std::map< std::string, double > & getAlphas(const char *con)
Definition: arbitrator.h:65
yarp::manager::Arbitrator::ruleCount
int ruleCount()
Definition: arbitrator.h:47
yarp::manager::Arbitrator::owner
Node * owner()
Definition: arbitrator.h:59
yarp::manager::Arbitrator::getRule
const char * getRule(const char *con)
Definition: arbitrator.h:38
yarp::manager::GraphicModel
Definition: node.h:28
yarp::manager::Arbitrator::getRuleMap
std::map< std::string, std::string > & getRuleMap()
Definition: arbitrator.h:46
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
yarp::manager::Arbitrator::setModelBase
void setModelBase(GraphicModel &mdl)
Definition: arbitrator.h:56
yarp::manager::Arbitrator::trainWeights
bool trainWeights()
Definition: arbitrator.cpp:118
yarp::manager::Arbitrator::getModelBase
GraphicModel & getModelBase()
Definition: arbitrator.h:55
yarp::manager::Arbitrator::addRule
void addRule(const char *con, const char *rule)
Class Arbitrator.
Definition: arbitrator.cpp:33
yarp::manager::Arbitrator::Arbitrator
Arbitrator(const char *szPort)
Definition: arbitrator.h:31