YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
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
13#include <yarp/manager/node.h>
15
16
17namespace yarp::manager {
18
19
25public:
26 Arbitrator() = default;
27 Arbitrator(const char* szPort) : strPort(szPort) {}
28 ~Arbitrator() = default;
29
30 void setPort(const char* szPort) { if(szPort) { strPort = szPort; } }
31
32 const char* getPort() { return strPort.c_str(); }
33
34 const char* getRule(const char* con)
35 {
36 if(con && (rules.find(con) != rules.end())) {
37 return rules[con].c_str();
38 }
39 return nullptr;
40 }
41
42 std::map<std::string, std::string>& getRuleMap() { return rules; }
43 int ruleCount() { return rules.size(); }
44
45 GraphicModel* getModel() { return model;}
46 void setModel(GraphicModel* mdl) { model = mdl; };
47
48 // modelBased is used to keep the graphic and geometric
49 // information which is directly loaded from application
50 // description file.
51 GraphicModel& getModelBase() { return modelBase;}
52 void setModelBase(GraphicModel& mdl) { modelBase = mdl; };
53
54 void setOwner(Node* owner){ appOwner = owner; }
55 Node* owner() { return appOwner; }
56
57 bool operator==(const Arbitrator& alt) const {
58 return (strPort == alt.strPort);
59 }
60
61 std::map<std::string, double>& getAlphas( const char* con) {
62 return alphas[con];
63 }
64
65 double getBias(const char* con) {
66 return biases[con];
67 }
68
69 void addRule(const char* con, const char* rule);
70 void removeRule(const char* con);
71 bool trainWeights(const char* opnd);
72 bool trainWeights();
73 bool validate();
74
75protected:
76
77private:
78 std::string strPort;
79 std::map<std::string, std::string> rules;
80 GraphicModel* model {nullptr};
81 GraphicModel modelBase;
82 Node* appOwner {nullptr};
83
84 std::map<std::string, std::map<std::string, double> > alphas;
85 std::map<std::string, double> biases;
86
87};
88
89
90typedef std::vector<Arbitrator> ArbContainer;
91typedef std::vector<Arbitrator>::iterator ArbIterator;
92
93} // namespace yarp::manager
94
95
96#endif // __YARP_MANAGER_ARBITRATOR__
Class port Arbitrator.
Definition arbitrator.h:24
std::map< std::string, double > & getAlphas(const char *con)
Definition arbitrator.h:61
GraphicModel & getModelBase()
Definition arbitrator.h:51
void setOwner(Node *owner)
Definition arbitrator.h:54
void addRule(const char *con, const char *rule)
Class Arbitrator.
bool operator==(const Arbitrator &alt) const
Definition arbitrator.h:57
double getBias(const char *con)
Definition arbitrator.h:65
Arbitrator(const char *szPort)
Definition arbitrator.h:27
std::map< std::string, std::string > & getRuleMap()
Definition arbitrator.h:42
const char * getRule(const char *con)
Definition arbitrator.h:34
const char * getPort()
Definition arbitrator.h:32
GraphicModel * getModel()
Definition arbitrator.h:45
void setModel(GraphicModel *mdl)
Definition arbitrator.h:46
void setModelBase(GraphicModel &mdl)
Definition arbitrator.h:52
void removeRule(const char *con)
void setPort(const char *szPort)
Definition arbitrator.h:30
a Node of a Graph
Definition node.h:64
std::vector< Arbitrator > ArbContainer
Definition arbitrator.h:90
std::vector< Arbitrator >::iterator ArbIterator
Definition arbitrator.h:91