本文整理汇总了C++中boost::random::mt19937类的典型用法代码示例。如果您正苦于以下问题:C++ mt19937类的具体用法?C++ mt19937怎么用?C++ mt19937使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了mt19937类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char** argv) {
ptime begin = microsec_clock::local_time();
random::mt19937 rng;
random::uniform_real_distribution<> uni(-1, 1);
int seed = lexical_cast<int>(argv[1]);
double Wi = lexical_cast<double>(argv[2]);
double Wf = lexical_cast<double>(argv[3]);
double mu = lexical_cast<double>(argv[4]);
double Ui = UWi(Wi);
double D = lexical_cast<double>(argv[5]);
double taui = lexical_cast<double>(argv[6]);
double tauf = lexical_cast<double>(argv[7]);
int ntaus = lexical_cast<int>(argv[8]);
// double tf = 2*tau;
// int nsteps = lexical_cast<int>(argv[9]);
double dt = lexical_cast<double>(argv[9]);
// int dnsav = lexical_cast<int>(argv[8]);
// int nsteps = (int) ceil(2 * tau / dt);
// double h = 2 * tau / nsteps;
int numthreads = lexical_cast<int>(argv[10]);
int resi = lexical_cast<int>(argv[11]);
// int resi = 0;
// if (argc > 9) {
// resi = lexical_cast<int>(argv[9]);
// }
int subresi = -1;
int seed2 = 0;
if (argc > 12) {
// subresi = lexical_cast<int>(argv[12]);
seed2 = lexical_cast<int>(argv[12]);
}
#ifdef AMAZON
// path resdir("/home/ubuntu/Results/Canonical Transformation Dynamical Gutzwiller");
path resdir("/home/ubuntu/Dropbox/Amazon EC2/Simulation Results/Canonical Transformation Dynamical Gutzwiller 2");
#else
path resdir("/Users/Abuenameh/Documents/Simulation Results/Canonical Transformation Dynamical Gutzwiller 2");
// path resdir("/Users/Abuenameh/Documents/Simulation Results/Dynamical Gutzwiller Hartmann Comparison");
#endif
if (!exists(resdir)) {
cerr << "Results directory " << resdir << " does not exist!" << endl;
exit(1);
}
ostringstream oss;
if (subresi == -1) {
oss << "res." << resi << ".txt";
}
else {
oss << "res." << resi << "." << subresi << ".txt";
}
path resfile = resdir / oss.str();
//#ifndef AMAZON
while (exists(resfile)) {
resi++;
oss.str("");
if (subresi == -1) {
oss << "res." << resi << ".txt";
}
else {
oss << "res." << resi << "." << subresi << ".txt";
}
resfile = resdir / oss.str();
}
//#endif
// if (seed == -1) {
// resi = -1;
if (seed < 0) {
resi = seed;
oss.str("");
oss << "res." << resi << ".txt";
resfile = resdir / oss.str();
}
vector<double> xi(L, 1);
rng.seed(seed);
if (seed > -1) {
for (int j = 0; j < L; j++) {
xi[j] = (1 + D * uni(rng));
}
}
// double Ui = UWi(Wi);
double mui = mu * Ui;
filesystem::ofstream os(resfile);
printMath(os, "seed", resi, seed);
printMath(os, "Delta", resi, D);
//.........这里部分代码省略.........
开发者ID:Abuenameh,项目名称:Canonical-Transformation-Dynamical-Gutzwiller-Casadi-Cvodes,代码行数:101,代码来源:main.cpp
示例2: seedrand
namespace sfs
{
boost::random::mt19937 randfast;
boost::random::mt19937_64 randfast64;
boost::random::random_device randomizer;
void seedrand()
{
randfast.seed(time(0));
randfast64.seed(time(0));
}
double random(double min, double max, bool slow)
{
boost::random::uniform_real_distribution<double> d(min, max);
if(slow)
{
return d(randomizer);
}
return d(randfast64);
}
float random(float min, float max, bool slow)
{
boost::random::uniform_real_distribution<float> d(min, max);
if(slow)
{
return d(randomizer);
}
return d(randfast);
}
template<typename T>
T random(T min, T max, bool slow)
{
boost::random::uniform_int_distribution<T> d(min, max);
if(slow)
{
return d(randomizer);
}
if(sizeof(T) >= 8)
{
// If we want 64-bit, use 64-bit generator.
return d(randfast64);
}
return d(randfast);
}
rgba random(rgba min, rgba max, bool slow)
{
rgba result;
result.r = random(min.r, max.r, slow);
result.g = random(min.g, max.g, slow);
result.b = random(min.b, max.b, slow);
result.a = random(min.a, max.a, slow);
return result;
}
vec3 random(vec3 min, vec3 max, bool slow)
{
vec3 result;
result.x = random(min.x, max.x, slow);
result.y = random(min.y, max.y, slow);
result.z = random(min.z, max.z, slow);
return result;
}
}
示例3: init
namespace robogen {
void init(unsigned int seed, std::string outputDirectory,
std::string confFileName, bool overwrite, bool saveAll);
void printUsage(char *argv[]) {
std::cout << std::endl << "USAGE: " << std::endl << " "
<< std::string(argv[0])
<< " <SEED, INTEGER> <OUTPUT_DIRECTORY, STRING> "
<< "<CONFIGURATION_FILE, STRING> [<OPTIONS>]" << std::endl
<< std::endl << "WHERE: " << std::endl
<< " <SEED> is a number to seed "
<< "the pseudorandom number generator." << std::endl << std::endl
<< " <OUTPUT_DIRECTORY> is the directory to write output "
<< "files to." << std::endl << std::endl
<< " <CONFIGURATION_FILE> is the evolution"
<< " configuration file to use." << std::endl << std::endl
<< "OPTIONS: " << std::endl << " --help" << std::endl
<< " Print all configuration options and exit."
<< std::endl << std::endl << " --overwrite" << std::endl
<< " Overwrite existing output file directory if it "
<< "exists." << std::endl
<< " (Default is to keep creating new output "
<< "directories with incrementing suffixes)." << std::endl
<< std::endl << " --save-all" << std::endl
<< " Save all individuals instead of just the generation"
<< "best." << std::endl << std::endl;
}
void printHelp() {
boost::shared_ptr<EvolverConfiguration> conf = boost::shared_ptr<
EvolverConfiguration>(new EvolverConfiguration());
conf->init("help");
std::cout << std::endl;
boost::shared_ptr<RobogenConfig> robotConf =
ConfigurationReader::parseConfigurationFile("help");
}
boost::shared_ptr<Population> population;
IndividualContainer children;
boost::shared_ptr<NeatContainer> neatContainer;
boost::shared_ptr<RobogenConfig> robotConf;
boost::shared_ptr<EvolverConfiguration> conf;
boost::shared_ptr<EvolverLog> log;
bool neat;
boost::shared_ptr<Selector> selector;
boost::shared_ptr<Mutator> mutator;
unsigned int generation;
boost::random::mt19937 rng;
std::vector<Socket*> sockets;
void parseArgsThenInit(int argc, char* argv[]) {
startRobogen();
// ---------------------------------------
// verify usage and load configuration
// ---------------------------------------
if (argc > 1 && std::string(argv[1]) == "--help") {
printUsage(argv);
printHelp();
exitRobogen(EXIT_SUCCESS);
}
if ((argc < 4)) {
printUsage(argv);
std::cout << "RUN: " << std::endl << std::endl
<< " " << std::string(argv[0])
<< " --help to see all configuration options."
<< std::endl << std::endl;
exitRobogen(EXIT_FAILURE);
}
unsigned int seed = atoi(argv[1]);
std::string outputDirectory = std::string(argv[2]);
std::string confFileName = std::string(argv[3]);
bool overwrite = false;
bool saveAll = false;
int currentArg = 4;
for (; currentArg < argc; currentArg++) {
if (std::string("--help").compare(argv[currentArg]) == 0) {
printUsage(argv);
printHelp();
exitRobogen(EXIT_SUCCESS);
} else if (std::string("--overwrite").compare(argv[currentArg]) == 0) {
overwrite = true;
} else if (std::string("--save-all").compare(argv[currentArg]) == 0) {
saveAll = true;
} else {
std::cerr << std::endl << "Invalid option: " << argv[currentArg]
<< std::endl << std::endl;
printUsage(argv);
exitRobogen(EXIT_FAILURE);
}
}
//.........这里部分代码省略.........
示例4: initialize
worker_input* initialize(double Wi, double Wf, double mu, vector<double>& xi, managed_shared_memory& segment) {
SX f = SX::sym("f", 2 * L * dim);
SX dU = SX::sym("dU", L);
SX J = SX::sym("J", L);
SX U0 = SX::sym("U0");
U0 = UW(Wi);
for (int i = 0; i < L; i++) {
J[i] = JWij(Wi * xi[i], Wi * xi[mod(i + 1)]);
dU[i] = UW(Wi * xi[i]) - U0;
}
SX E = energy(f, J, U0, dU, mu).real();
SX g = SX::sym("g", L);
for (int i = 0; i < L; i++) {
g[i] = 0;
for (int n = 0; n < dim; n++) {
g[i] += f[2 * (i * dim + n)] * f[2 * (i * dim + n)] + f[2 * (i * dim + n) + 1] * f[2 * (i * dim + n) + 1];
}
}
SXFunction nlp("nlp", nlpIn("x", f), nlpOut("f", E, "g", g));
NlpSolver solver("solver", "ipopt", nlp, make_dict("hessian_approximation", "limited-memory", "linear_solver", "ma86", "print_level", 0, "print_time", false, "obj_scaling_factor", 1));
boost::random::mt19937 rng;
boost::random::uniform_real_distribution<> uni(-1, 1);
vector<double> xrand(2 * L*dim, 1);
rng.seed();
for (int i = 0; i < 2 * L * dim; i++) {
xrand[i] = uni(rng);
}
map<string, DMatrix> arg;
arg["lbx"] = -1;
arg["ubx"] = 1;
arg["x0"] = xrand;
arg["lbg"] = 1;
arg["ubg"] = 1;
map<string, DMatrix> res = solver(arg);
vector<double> x0 = res["x"].nonzeros();
// vector<double> x0 = xrand;
// cout << "x0 = " << ::math(x0) << endl;
// cout << "E0 = " << ::math(res["f"].toScalar()) << endl;
vector<complex<double>> x0i(dim);
for (int i = 0; i < L; i++) {
for (int n = 0; n <= nmax; n++) {
x0i[n] = complex<double>(x0[2 * (i * dim + n)], x0[2 * (i * dim + n) + 1]);
}
double nrm = sqrt(abs(dot(x0i, x0i)));
for (int n = 0; n <= nmax; n++) {
x0[2 * (i * dim + n)] /= nrm;
x0[2 * (i * dim + n) + 1] /= nrm;
}
}
// cout << "nlp: " << ::math(nlp(vector<DMatrix>{x0, vector<double>()})[0].toScalar()) << endl;
void_allocator void_alloc(segment.get_segment_manager());
worker_input* input = segment.construct<worker_input>("input")(void_alloc);
input->U0 = UW(Wi);
for (int i = 0; i < L; i++) {
input->J0.push_back(JWij(Wi * xi[i], Wi * xi[mod(i + 1)]));
}
for (int i = 0; i < 2 * L * dim; i++) {
input->x0.push_back(x0[i]);
}
for (int i = 0; i < L; i++) {
complex_vector f0i(dim, void_alloc);
for (int n = 0; n <= nmax; n++) {
f0i[n] = complex<double>(x0[2 * (i * dim + n)], x0[2 * (i * dim + n) + 1]);
}
input->f0.push_back(f0i);
}
input->Wi = Wi;
input->Wf = Wf;
input->mu = mu;
for (int i = 0; i < L; i++) {
input->xi.push_back(xi[i]);
}
return input;
}
示例5: main
int main(int argc, char** argv) {
build_odes();
return 0;
// build_odes();
// return 0;
ptime begin = microsec_clock::local_time();
random::mt19937 rng;
random::uniform_real_distribution<> uni(-1, 1);
int seed = lexical_cast<int>(argv[1]);
if (seed != -1) {
double Wi = lexical_cast<double>(argv[2]);
double Wf = lexical_cast<double>(argv[3]);
double mu = lexical_cast<double>(argv[4]);
double Ui = UWi(Wi);
double D = lexical_cast<double>(argv[5]);
double taui = lexical_cast<double>(argv[6]);
double tauf = lexical_cast<double>(argv[7]);
int ntaus = lexical_cast<int>(argv[8]);
int numthreads = lexical_cast<int>(argv[9]);
int resi = lexical_cast<int>(argv[10]);
// int integrator = lexical_cast<int>(argv[11]);
std::string intg = argv[11];
double dt = lexical_cast<double>(argv[12]);
#ifdef AMAZON
// path resdir("/home/ubuntu/Results/Canonical Transformation Dynamical Gutzwiller");
path resdir("/home/ubuntu/Dropbox/Amazon EC2/Simulation Results/CTDG");
#else
path resdir("/Users/Abuenameh/Documents/Simulation Results/Canonical Transformation Dynamical Gutzwiller 2");
// path resdir("/Users/Abuenameh/Documents/Simulation Results/Dynamical Gutzwiller Hartmann Comparison");
#endif
if (!exists(resdir)) {
cerr << "Results directory " << resdir << " does not exist!" << endl;
exit(1);
}
ostringstream oss;
oss << "res." << resi << ".txt";
path resfile = resdir / oss.str();
//#ifndef AMAZON
while (exists(resfile)) {
resi++;
oss.str("");
oss << "res." << resi << ".txt";
resfile = resdir / oss.str();
}
//#endif
if (seed < 0) {
resi = seed;
oss.str("");
oss << "res." << resi << ".txt";
resfile = resdir / oss.str();
}
vector<double> xi(L, 1);
rng.seed(seed);
if (seed > -1) {
for (int j = 0; j < L; j++) {
xi[j] = (1 + D * uni(rng));
}
}
// double Ui = UWi(Wi);
double mui = mu * Ui;
filesystem::ofstream os(resfile);
printMath(os, "int", resi, intg);
printMath(os, "seed", resi, seed);
printMath(os, "Delta", resi, D);
printMath(os, "dt", resi, dt);
printMath(os, "mures", resi, mui);
printMath(os, "Ures", resi, Ui);
printMath(os, "xires", resi, xi);
os << flush;
printMath(os, "Wires", resi, Wi);
printMath(os, "Wfres", resi, Wf);
os << flush;
cout << "Res: " << resi << endl;
struct shm_remove {
shm_remove() {
shared_memory_object::remove("SharedMemory");
}
~shm_remove() {
//.........这里部分代码省略.........
示例6: init_rand_gen
static void init_rand_gen()
{
int fd = open("/dev/urandom", O_RDONLY);
if (fd != -1) {
uint32_t seed;
read(fd, &seed, sizeof(uint32_t));
g_mt_rand.seed(seed);
close(fd);
}
else {
g_mt_rand.seed(time(NULL));
}
}
示例7: main
int main() {
gen.seed(static_cast<unsigned int>(std::time(0)));
const int beam_size = 3;
const int vocab_size = 10;
const int start_symbol = 0;
const int end_symbol = 1;
const int max_decoding_length = 30;
const int min_decoding_length = 10;
const int source_length = 10;
const precision penalty = 3;
decoder<precision> d(beam_size,vocab_size,start_symbol,end_symbol,
max_decoding_length,min_decoding_length,penalty,"");
Eigen::Matrix<precision,Eigen::Dynamic, Eigen::Dynamic> outputDist;
Eigen::Matrix<precision, 1, Eigen::Dynamic> normalization;
outputDist.resize(vocab_size,beam_size);
normalization.resize(1,beam_size);
init_output_dist(outputDist,normalization);
d.init_decoder();
for(int i=0; i<20; i++) {
init_output_dist(outputDist,normalization);
d.expand_hypothesis(outputDist);
d.print_current_hypotheses();
}
d.finish_current_hypotheses(outputDist);
d.print_current_hypotheses();
}
示例8: Seed
void UnsyncedRNG::Seed(unsigned seed)
{
#ifdef USE_BOOST_RNG
rng.seed(seed);
#else
randSeed = seed;
#endif
}
示例9: getRandomNumber
int Helper::getRandomNumber(const int _min, const int _max)
{
randomGenerator.seed(std::time(0));
boost::random::uniform_int_distribution<> dist(_min, _max);
return dist(randomGenerator);
}
示例10: random_initialize
// Initialize the seed of the random number generator
void random_initialize(unsigned int seed) {
random_gen.seed(seed);
}
示例11: main
int main() {
string x, y, opcode;
string cmd;
boost::random::uniform_int_distribution<> dist32bit(0, 2147483647);
boost::random::uniform_int_distribution<> dist3bit(0, 4);
vector<pair<string,string> > db;
for(int i = 0; i < 5000; i++) {
gen.seed(static_cast<unsigned int>(time(0) + getpid()) + i);
int r0 = dist32bit(gen);
int r1 = dist32bit(gen);
int r2 = dist3bit(gen);
//cout << r0 << " " << r1 << " " << r2 << endl;
bitset<32> t0(r0);
bitset<32> t1(r1);
bitset<3> t2(r2);
x = t0.to_string();
y = t1.to_string();
opcode = t2.to_string();
//cout << x << " " << y << " " << opcode << endl;
cmd = "vvp a.out +x=" + x + " +y=" + y + " +opcode=" + opcode; // Program to run or "wrap"
string out = exec(cmd);
//cout << out;
int index;
string delay;
const char* process = out.c_str();
for(int i = strlen(process) - 1; i >= 0; i--) {
if(process[i] == ' ') { index = i; break; }
}
for(int i = index + 1; i < strlen(process); i++) {
delay = delay + process[i];
}
add(delay, opcode, db);
cout << i << endl;
}
int j;
ofstream f("5krandominputs.txt"); // Output file
for(vector<pair<string,string> >::const_iterator i = db.begin(); i != db.end(); ++i) {
string first = (*i).first;
string second = (*i).second;
trim(first);
trim(second);
string w = first + " " + second + '\n';
f << w;
int j;
cout << "writing..." << j++ << endl;
}
}
示例12: seed
void seed(int seed)
{
gen.seed(seed);
}
示例13: dist
RandomInt(int min, int max, int seed)
: dist(min, max)
{
gen.seed(seed);
}
示例14: RandomSeed
/**
* Set the random seed used by the random functions (Random() and RandInt()).
* The seed is casted to a 32-bit integer before being given to the random
* number generator, but a size_t is taken as a parameter for API consistency.
*
* @param seed Seed for the random number generator.
*/
inline void RandomSeed(const size_t seed)
{
randGen.seed((uint32_t) seed);
srand((unsigned int) seed);
}
示例15: reset
void reset(int min, int max, int seed)
{
dist = boost::random::uniform_int_distribution<>(min, max);
gen.seed(seed);
}