random_attribute_generator.cpp 1.58 KB
Newer Older
Jonas Seidel's avatar
Jonas Seidel committed
1
2
3
4
5
6
7
8
9
#include "random_attribute_generator.h"

random_attribute_generator::random_attribute_generator(
  std::map<
    std::string,
    std::tuple<opt_dir, integrality, double, double>
  > data
){
  for(std::pair<std::string, std::tuple<opt_dir, integrality, double, double> > pair : data){
jonasseidel's avatar
jonasseidel committed
10
    assert(std::get<2>(pair.second) <= std::get<3>(pair.second) );
Jonas Seidel's avatar
Jonas Seidel committed
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

    std::pair<opt_dir, integrality> constr_data = {std::get<0>(pair.second), std::get<1>(pair.second)};
    this->_constr_data.insert({pair.first, constr_data});
    if(constr_data.second == Integral){
      this->_integral_dist.insert({pair.first, std::uniform_int_distribution<>(std::get<2>(pair.second), std::get<3>(pair.second)) });
    }else{
      this->_continuous_dist.insert({pair.first, std::uniform_real_distribution<>(std::get<2>(pair.second), std::get<3>(pair.second)) });
    }
  }
}

std::map<std::string, Attribute> random_attribute_generator::next(){
  std::map<std::string, Attribute> instance;
  for(std::pair<std::string, std::pair<opt_dir, integrality> > constr_pair : this->_constr_data){
    if(constr_pair.second.second == Integral){
      instance.insert({constr_pair.first, {constr_pair.second.first, (double) (this->_integral_dist.find(constr_pair.first)->second)(this->_engine), constr_pair.second.second}} );
    }else{
      instance.insert({constr_pair.first, {constr_pair.second.first, (this->_continuous_dist.find(constr_pair.first)->second)(this->_engine), constr_pair.second.second}});
    }
  }
  return instance;
}

void random_attribute_generator::operator>>(std::map<std::string, Attribute>& var){
  var = this->next();
}