Commit c14332fd by Tianqi Yang

feat(sim): use geometric distribution to get the next day

parent db20756e
......@@ -2,3 +2,6 @@ main
Debug
.vs
*.vcxproj*
*.in
*.out
tmp
......@@ -2,7 +2,7 @@
#include "markov_chain.h"
using namespace std;
const int SIM_DAYS = 100000;
const int SIM_DAYS = 10000000;
int main ()
{
......
......@@ -63,12 +63,11 @@ double simulate_prob ( double lambda, double prob_day, int sim_times )
{
mt19937 rand_gen ( static_cast < unsigned > ( chrono::system_clock::now ().time_since_epoch ().count () ) );
poisson_distribution < int > poisson ( lambda );
uniform_real_distribution < double > uniform ( 0.0, 1.0 );
geometric_distribution < int > geometric ( prob_day );
State current_state;
long long total_cost = 0, used_coupon = 0;
for ( int go_time = 0; go_time < sim_times; ++go_time ) {
int day = 1;
while ( uniform ( rand_gen ) >= prob_day ) ++day;
int day = geometric ( rand_gen ) + 1;
current_state.pass_day ( day );
int current_cost = poisson ( rand_gen );
total_cost += current_cost;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment