33 void Arbitrator::addRule(
const char* con,
const char* rule)
38 std::map<std::string, double> w;
44 void Arbitrator::removeRule(
const char* con)
46 rules.erase(rules.find(con));
47 alphas.erase(alphas.find(con));
48 biases.erase(biases.find(con));
65 bool Arbitrator::trainWeights(
const char* opnd)
71 string rule = getRule(opnd);
74 std::map<std::string, double> w;
81 std::map<string, string>::iterator itr;
82 for(itr=rules.begin(); itr!=rules.end(); itr++)
86 rule = string(opnd) +
" : " + rule;
87 if(!parser.
parse(rule))
94 biases[opnd] = trainer.
getBias();
96 std::vector<double> alf = trainer.
getAlphas();
97 std::map<std::string, double> w;
99 std::map<std::string, bool>::iterator itr;
100 std::map<std::string, bool> operands = parser.
getOperands();
102 for(itr=operands.begin(); itr!=operands.end(); itr++)
104 w[itr->first] = alf[i];
111 logger->
addError(
"Maximum number of iterations is reached without finding any solution. Check for the correctness of the expression logic.");
118 bool Arbitrator::trainWeights()
123 std::map<string, string>::iterator itr;
124 for(itr=rules.begin(); itr!=rules.end(); itr++)
125 bAllOk &= trainWeights((itr->first).c_str());
130 bool Arbitrator::validate()
139 int n = alphas.size();
144 std::map<std::string, std::map<std::string, double> >::iterator itr;
145 std::map<std::string, std::map<std::string, double> >::iterator jtr;
148 for(itr=alphas.begin(); itr!=alphas.end(); itr++)
150 std::map<std::string, double>& w = itr->second;
152 for(jtr=alphas.begin(); jtr!=alphas.end(); jtr++)
154 std::string opnd = jtr->first;
155 if(w.find(opnd) != w.end())
156 A(row,col) = w[opnd];
169 for(
size_t i=0; i<real.
size(); i++)
171 if((
float)fabs(real[i]) >= 1.0)
174 logger->
addError(
"Inconsistency in logical expressions. This will result an unstable arbitration system!");
212 #else //WITH_YARPMATH
213 logger->
addWarning(
"Yarpmanager is compiled without libYarpMath. Your compact logical expression might result an unstable arbitration system!");
215 #endif //WITH_YARPMATH