Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
I
Intro2MM-Homework1
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tianqi Yang
Intro2MM-Homework1
Commits
c14332fd
Commit
c14332fd
authored
Oct 08, 2019
by
Tianqi Yang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(sim): use geometric distribution to get the next day
parent
db20756e
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
6 additions
and
4 deletions
+6
-4
.gitignore
.gitignore
+3
-0
main.cpp
main.cpp
+1
-1
markov_chain.cpp
markov_chain.cpp
+2
-3
No files found.
.gitignore
View file @
c14332fd
...
...
@@ -2,3 +2,6 @@ main
Debug
.vs
*.vcxproj*
*.in
*.out
tmp
main.cpp
View file @
c14332fd
...
...
@@ -2,7 +2,7 @@
#include "markov_chain.h"
using
namespace
std
;
const
int
SIM_DAYS
=
100000
;
const
int
SIM_DAYS
=
100000
00
;
int
main
()
{
...
...
markov_chain.cpp
View file @
c14332fd
...
...
@@ -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
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment