int cpp_main(int,char*[]) { size_t npg = 10; size_t nCell = 100000; size_t nParticles = nCell * npg; { vectorlist vl(nParticles, nCell); { boost::progress_timer tm; randomshuffler shuffler(nCell); vl.for_each_p( boost::bind(boost::ref(shuffler),_1) ); std::cout << shuffler.total_moves() << std::endl; vl.redistribute(); } } { sortedvector vl(nParticles, nCell); { boost::progress_timer tm; randomshuffler shuffler(nCell); vl.for_each_p( boost::bind(boost::ref(shuffler),_1) ); std::cout << shuffler.total_moves() << std::endl; vl.redistribute(); } } return boost::exit_success; }
double IterativeTableScoreFunction::computePvalue(int nb_permutations, const Dataset& dataset, int seed) { PvaluesComputer pvc; StdShuffler shuffler(seed, 0); IterativeTableScoresPvaluesComputable comp(*this, dataset, shuffler); pvc.computePvalues(nb_permutations, comp); return pvc.get_pvalues().front(); }
double IterativeTableScoreFunction::computeScore(const Dataset& dataset) { StdShuffler shuffler(0, 0); IterativeTableScoresPvaluesComputable comp(*this, dataset, shuffler); vector<double> scores; comp.compute( scores ); return scores.front(); }
int main(int, char**) { RandomLib::Random r; r.Reseed(); #if HAVE_LAMBDA std::cout << "Illustrate calling STL routines with lambda expressions\n"; #else std::cout << "Illustrate calling STL routines without lambda expressions\n"; #endif std::cout << "Using " << r.Name() << "\n" << "with seed " << r.SeedString() << "\n\n"; std::vector<unsigned> c(10); // Fill with unsigned in [0, 2^32) #if HAVE_LAMBDA std::generate(c.begin(), c.end(), [&r]() throw() -> unsigned { return r(); }); #else std::generate<std::vector<unsigned>::iterator, RandomLib::Random&> (c.begin(), c.end(), r); #endif std::vector<double> b(10); // Fill with normal deviates #if HAVE_LAMBDA RandomLib::NormalDistribution<> nf; std::generate(b.begin(), b.end(), [&r, &nf]() throw() -> double { return nf(r,0.0,2.0); }); #else std::generate(b.begin(), b.end(), RandomNormal<>(r,0.0,2.0)); #endif std::vector<int> a(20); // How to shuffle large vectors #if HAVE_LAMBDA int i = 0; std::generate(a.begin(), a.end(), [&i]() throw() -> int { return i++; }); std::random_shuffle(a.begin(), a.end(), [&r](unsigned long long n) throw() -> unsigned long long { return r.Integer<unsigned long long>(n); }); #else for (size_t i = 0; i < a.size(); ++i) a[i] = int(i); RandomInt<unsigned long long> shuffler(r); std::random_shuffle(a.begin(), a.end(), shuffler); #endif return 0; }
int main() { /* Repeat Loop Head */ char repeater('0'); while( repeater == '0') { /* Constants */ // Locations const int BUILDINGS(6), CTLM(0), MEYER_HALL(1), COOLBAUGH_HALL(2), GREEN_CENTER(3), BERTHOUD_HALL(4), BROWN_HALL(5); const string BNAMES[] = { "CTLM", "Meyer Hall", "Coolbaugh Hall", "Green Center", "Berthoud Hall", "Brown Hall", "Free Time" }; const string LNAMES[] = { "CTLM", "Meyer Hall", "Coolbaugh Hall", "Green Center", "Berthoud Hall", "Brown Hall", "Kafadar", "Library", "Student Center", "Rec Center" }; // Commons const int COMMONS(4), KAFADAR(0), LIBRARY(1), STUDENT_CENTER(2), REC_CENTER(3); // Time Specifications const int DAYS(2); const int HOURS(8); const int SIMWEEKS = 2; const int DAYS_IN_WEEK = 7; const int SATURDAY = 5; const string DNAMES[] = { "Monday, Wednesday, Friday", "Tues, Thursday" }; // Other Details const int LECTURES(5); const int FREE_BLOCK(BUILDINGS); /* Variables */ int schedule[DAYS][HOURS]; int locationCount[BUILDINGS + COMMONS] = {}; /* Header */ cout << "-- Schedule Simulator and Such --" << endl << endl; srand(readSeed()); /* Schedule Generator */ for(int i(0); i < DAYS; i++) { blocking( schedule[i], HOURS, BUILDINGS, LECTURES ); shuffler( schedule[i], HOURS ); } /* Simulate Multiple Weeks */ for( int d(0); d < SIMWEEKS * DAYS_IN_WEEK; d++ ) { if( d % DAYS_IN_WEEK < SATURDAY ) { // not the weekend for( int h(0); h < HOURS; h++ ) { int b = schedule[d % DAYS_IN_WEEK % DAYS][h]; // reduce d to either 0 or 1 (MWF or TR) if( b == FREE_BLOCK ) { // Pick a random common area int c = rand() % COMMONS; // choose one at random // add it to the count locationCount[BUILDINGS + c]++; } else { // in a building locationCount[b]++; } } } } /* Footer */ cout << endl; for( int d(0); d < DAYS; d++ ) { cout << DNAMES[d] << ": " << endl; for( int h(0); h < HOURS; h++ ) { cout << BNAMES[ schedule[d][h] ] << endl; } cout << endl << endl; } cout << endl << endl; for( int i(0); i < COMMONS + BUILDINGS; i++ ) { cout << LNAMES[i] << ": " << locationCount[i] << endl; } cout << endl << endl << endl << endl; /* Repeat Loop Foot */ repeater = '2'; while( repeater != '0' && repeater != '1') { cout << "0 to continue, 1 to quit." << endl; cin >> repeater; } cout << endl << endl; } system("PAUSE"); return 0; }