void test_sum_rng( int count ) { std::cout << "Test 2 gestartet" << std::endl; typedef std::vector<std::pair<std::vector<double>, boost::any > > t_kv_pair_vec; t_kv_pair_vec test_vector; // ein paar Beispielplaene typedef boost::mt19937 t_rng; t_rng m_rng; boost::variate_generator<t_rng&, boost::uniform_int<> > uni_gen(m_rng, boost::uniform_int<>(1,100)); std::ofstream fout("weighted_sum.dat"); for (int i = 1; i < count; i++) { boost::any value = i; int wert1 = uni_gen(); int wert2 = uni_gen(); fout << wert1 << "," << wert2 << std::endl; std::vector<double> keys; keys.push_back( wert1 ); keys.push_back( wert2 ); test_vector.push_back( std::pair<std::vector<double>, boost::any >(keys, value) ); } // print for (t_kv_pair_vec::iterator it = test_vector.begin(); it != test_vector.end(); it++) { std::cout << "[" << it->first[0] << " ; " << it->first[1] << "] -> "; std::cout << boost::any_cast<int>(it->second) << std::endl; } std::cout << "Generated sample costs" << std::endl; std::cout << "Reading weights from config" << std::endl; double NET_DSMS_WEIGHTS = config::instance().get_value<double>( "NET_DSMS_WEIGHTS" ); double NET_INQP_WEIGHTS = config::instance().get_value<double>( "NET_INQP_WEIGHTS" ); std::vector<double> weights; weights.push_back( NET_DSMS_WEIGHTS ); weights.push_back( NET_INQP_WEIGHTS ); weighted_sum *ws = new weighted_sum( weights ); std::cout << "The best plan for this combination is " << boost::any_cast<int>( ws->get_optim( test_vector ) ) << std::endl; }
void skyline_dim_test(int count) { std::cout << "2 dimensional Skyline erstellen" << std::endl; typedef std::vector<std::pair<std::vector<double>, boost::any > > t_kv_pair_vec; t_kv_pair_vec test_vector; // ein paar Beispielplaene typedef boost::mt19937 t_rng; t_rng m_rng; boost::variate_generator<t_rng&, boost::uniform_int<> > uni_gen(m_rng, boost::uniform_int<>(1,100)); std::ofstream fout("skyline_random.dat"); for (int i = 1; i < count; i++) { boost::any value = i; int wert1 = uni_gen(); int wert2 = uni_gen(); fout << wert1 << "," << wert2 << std::endl; std::vector<double> keys; keys.push_back( wert1 ); keys.push_back( wert2 ); test_vector.push_back( std::pair<std::vector<double>, boost::any >(keys, value) ); } // print for (t_kv_pair_vec::iterator it = test_vector.begin(); it != test_vector.end(); it++) { std::cout << "[" << it->first[0] << " ; " << it->first[1] << "] -> "; std::cout << boost::any_cast<int>(it->second) << std::endl; } std::cout << "Generated sample costs" << std::endl; skyline *sky = new skyline(); sky->get_skyline( test_vector ); std::cout << "Skyline finished" << std::endl; std::cout << "The pareto front is: " << std::endl; sky->print_pareto_set(); std::cout << std::endl; std::cout << std::endl; }
// Generate number using a normal distribution double norm_gen( double mu, \ double sigma ) { #if DEBUG__NORM_GEN cout << "mu: " << mu << endl; cout << "sigma: " << sigma << endl; #endif // Procedure to generate values from a normal distribution (Wikipedia) double U, V, S; do { U = uni_gen( -1.0, 1.0 ); V = uni_gen( -1.0, 1.0 ); S = U * U + V * V; #if DEBUG__NORM_GEN cout << "U: " << U << endl; cout << "V: " << V << endl; cout << "S: " << S << endl; #endif } while ( S >= 1 ); #if DEBUG__NORM_GEN double rand_num = mu + sigma * ( U * sqrt( -2 * log( S ) / S ) ); cout << "rand_num: " << rand_num << endl; return rand_num; #else // Stretch and shift the distribution return mu + sigma * ( U * sqrt( -2 * log( S ) / S ) ); #endif }
void random_boost() { typedef boost::minstd_rand base_generator_type; //typedef boost::mt19937 base_generator_type; base_generator_type baseGenerator(static_cast<unsigned int>(std::time(NULL))); // uniform (integer) { typedef boost::uniform_int<> distribution_type; typedef boost::variate_generator<base_generator_type &, distribution_type> generator_type; generator_type die_gen(baseGenerator, distribution_type(1, 6)); for(int j = 0; j < 10; ++j) { //baseGenerator.seed(42u); // caution: generate repetitive sample for(int i = 0; i < 10; ++i) std::cout << die_gen() << ' '; std::cout << std::endl; } std::cout << std::endl; } // uniform (real) { typedef boost::uniform_real<> distribution_type; typedef boost::variate_generator<base_generator_type &, distribution_type> generator_type; baseGenerator.seed(static_cast<unsigned int>(std::time(NULL))); generator_type uni_gen(baseGenerator, distribution_type(0, 1)); for(int j = 0; j < 10; ++j) { //baseGenerator.seed(42u); // caution: generate repetitive sample for (int i = 0; i < 10; ++i) std::cout << uni_gen() << ' '; std::cout << std::endl; } std::cout << std::endl; } // normal { typedef boost::normal_distribution<> distribution_type; typedef boost::variate_generator<base_generator_type &, distribution_type> generator_type; const double mean = 1000.0; const double sigma = 100.0; generator_type normal_gen(baseGenerator, distribution_type(mean, sigma)); for(int j = 0; j < 10; ++j) { //baseGenerator.seed(42u); // caution: generate repetitive sample for(int i = 0; i < 10; ++i) std::cout << normal_gen() << ' '; std::cout << std::endl; } std::cout << std::endl; } // //base_generator_type saved_generator = baseGenerator; //assert(baseGenerator == saved_generator); // //std::ofstream stream("rng.saved", std::ofstream::trunc); //stream << baseGenerator; }
float RandomGenerator::rand_uniform_distribution() { return uni_gen(); }