Skip to content
Snippets Groups Projects
Commit 3d42df63 authored by jgatt's avatar jgatt
Browse files

change init_prob fun. Now all unset probability are set to 0

parent 776f1cd9
No related branches found
No related tags found
1 merge request!12Merge Request multibehavior
......@@ -30,38 +30,20 @@ void DMUserMultiBehavior::init_prob(const rapidjson::Value &param,uint_fast32_t
//Red window probability initialization
std::vector<double> red_prob (5,-1.0);
std::vector<bool> red_set_prob (5,false);
std::vector<double> red_prob (5,0.0);
std::string red_config[] = {"red_prob_degrad","red_prob_see_you_later",
"red_prob_reconfig","red_prob_renonce","red_prob_rigid"};
double total_unset_probability = 1.0;
double total_random_set_prob = 0.0;
red_prob_total=0.0;
//We set the probability either by reading json data or by drawing it randomly
for (std::vector<double>::size_type i =0 ; i < red_prob.size();i++){
std::string current_prob = red_config[i];
if(param.HasMember(current_prob.c_str())){
/*PPK_ASSERT(param[current_prob.c_str()].IsDouble()
PPK_ASSERT(param[current_prob.c_str()].IsDouble()
&& param[current_prob.c_str()].GetDouble()>=0.0,
"Error every specified red probability should be a non-negative Double");*/
red_set_prob[i] = true;
"Error every specified red probability should be a non-negative Double");
red_prob[i] = param[current_prob.c_str()].GetDouble();
total_unset_probability -= red_prob[i];
red_prob_total += red_prob[i];
}
else
{
red_prob[i] = distribution(random_gen);
total_random_set_prob += red_prob[i];
}
}
// We normalize the probability that wasn't set by user such that the total
// probability is 1.0
double random_set_coeff = total_unset_probability/total_random_set_prob;
for (std::vector<double>::size_type i= 0 ; i < red_prob.size();i++){
if(not red_set_prob[i]){
red_prob[i]=red_prob[i]* random_set_coeff;
}
red_prob_total+= red_prob[i];
}
//we save the result in the used probability variable
red_prob_degrad = red_prob[0];
......@@ -71,38 +53,20 @@ void DMUserMultiBehavior::init_prob(const rapidjson::Value &param,uint_fast32_t
// Yellow probability Initialization
std::vector<double> yellow_prob (3,-1.0);
std::vector<bool> yellow_set_prob (3,false);
std::vector<double> yellow_prob (3,0.0);
std::string yellow_config[] = {"yellow_prob_degrad",
"yellow_prob_reconfig","yellow_prob_rigid"};
total_unset_probability = 1.0;
total_random_set_prob = 0.0;
yellow_prob_total=0.0;
//We set the probability either by reading json data or by drawing it randomly
for (std::vector<double>::size_type i =0 ; i < yellow_prob.size();i++){
std::string current_prob = yellow_config[i];
if(param.HasMember(current_prob.c_str())){
/*PPK_ASSERT(param[current_prob.c_str()].IsDouble()
PPK_ASSERT(param[current_prob.c_str()].IsDouble()
&& param[current_prob.c_str()].GetDouble()>=0.0,
"Error every specified yellow probability should be a non-negative Double");*/
yellow_set_prob[i] = true;
"Error every specified yellow probability should be a non-negative Double");
yellow_prob[i] = param[current_prob.c_str()].GetDouble();
total_unset_probability -= yellow_prob[i];
}
else
{
yellow_prob[i] = distribution(random_gen);
total_random_set_prob += yellow_prob[i];
}
}
// We normalize the probability that wasn't set by user such that the total
// probability is 1.0
random_set_coeff = total_unset_probability/total_random_set_prob;
for (std::vector<double>::size_type i= 0 ; i < yellow_prob.size();i++){
if(not yellow_set_prob[i]){
yellow_prob[i]=yellow_prob[i]* random_set_coeff;
yellow_prob_total += yellow_prob[i];
}
yellow_prob_total+= yellow_prob[i];
}
yellow_prob_degrad= yellow_prob[0];
yellow_prob_reconfig = yellow_prob[1];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment