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
96ec9f28
Commit
96ec9f28
authored
Oct 10, 2019
by
Tianqi Yang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(markov): add supplement support in main
parent
27088796
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
9 deletions
+17
-9
gen.py
gen.py
+5
-2
main.cpp
main.cpp
+12
-7
No files found.
gen.py
View file @
96ec9f28
...
@@ -3,7 +3,10 @@
...
@@ -3,7 +3,10 @@
import
numpy
as
np
import
numpy
as
np
import
math
import
math
print
(
' '
.
join
(
list
(
map
(
str
,
range
(
100
,
201
,
2
)
)
)
)
)
print
(
' '
.
join
(
list
(
map
(
str
,
range
(
100
,
501
,
5
)
)
)
)
)
a
=
np
.
logspace
(
math
.
log
(
0.0001
,
10
),
math
.
log
(
0.01
,
10
),
20
)
.
tolist
()[
0
:
-
1
]
+
np
.
logspace
(
math
.
log
(
0.01
,
10
),
math
.
log
(
1
,
10
),
40
)
.
tolist
()
a
=
np
.
logspace
(
math
.
log
(
0.0001
,
10
),
math
.
log
(
0.01
,
10
),
40
)
.
tolist
()[
0
:
-
1
]
+
np
.
logspace
(
math
.
log
(
0.01
,
10
),
math
.
log
(
1
,
10
),
80
)
.
tolist
()
print
(
' '
.
join
(
list
(
map
(
str
,
a
)
)
)
)
a
=
[
0
,
5
,
10
,
15
,
20
,
30
,
40
,
50
]
print
(
' '
.
join
(
list
(
map
(
str
,
a
)
)
)
)
print
(
' '
.
join
(
list
(
map
(
str
,
a
)
)
)
)
main.cpp
View file @
96ec9f28
...
@@ -10,14 +10,15 @@ const int SIM_TIMES = 100000;
...
@@ -10,14 +10,15 @@ const int SIM_TIMES = 100000;
struct
Task
struct
Task
{
{
Task
(
int
_lambda
,
double
_p
)
Task
(
int
_lambda
,
double
_p
,
int
_threshold
)
:
lambda
(
_lambda
),
p
(
_p
)
:
lambda
(
_lambda
),
p
(
_p
)
,
threshold
(
_threshold
)
{
{
}
}
int
lambda
;
int
lambda
;
double
p
;
double
p
;
int
threshold
;
};
};
thread_safe_queue
<
Task
>
task_queue
;
thread_safe_queue
<
Task
>
task_queue
;
...
@@ -44,13 +45,13 @@ void run_thread ( ofstream &RES, mutex &mut, ProgressBar &progress_bar )
...
@@ -44,13 +45,13 @@ void run_thread ( ofstream &RES, mutex &mut, ProgressBar &progress_bar )
if
(
current_task
.
lambda
==
-
1
)
break
;
if
(
current_task
.
lambda
==
-
1
)
break
;
vector
<
double
>
result
;
vector
<
double
>
result
;
for
(
int
repeat
=
0
;
repeat
<
REPEAT
;
++
repeat
)
{
for
(
int
repeat
=
0
;
repeat
<
REPEAT
;
++
repeat
)
{
result
.
push_back
(
simulate_prob
(
current_task
.
lambda
,
current_task
.
p
,
SIM_TIMES
)
);
result
.
push_back
(
simulate_prob
(
current_task
.
lambda
,
current_task
.
p
,
SIM_TIMES
,
current_task
.
threshold
)
);
++
progress_bar
;
++
progress_bar
;
}
}
{
{
lock_guard
<
mutex
>
lock
(
mut
);
lock_guard
<
mutex
>
lock
(
mut
);
RES
<<
"---start"
<<
endl
;
RES
<<
"---start"
<<
endl
;
RES
<<
current_task
.
lambda
<<
" "
<<
current_task
.
p
<<
endl
;
RES
<<
current_task
.
lambda
<<
" "
<<
current_task
.
p
<<
" "
<<
current_task
.
threshold
<<
endl
;
for
(
auto
x
:
result
)
{
for
(
auto
x
:
result
)
{
RES
<<
x
<<
endl
;
RES
<<
x
<<
endl
;
}
}
...
@@ -63,25 +64,29 @@ int main ()
...
@@ -63,25 +64,29 @@ int main ()
{
{
vector
<
int
>
lambdas
=
read_line_to_array
<
int
>
();
vector
<
int
>
lambdas
=
read_line_to_array
<
int
>
();
vector
<
double
>
ps
=
read_line_to_array
<
double
>
();
vector
<
double
>
ps
=
read_line_to_array
<
double
>
();
vector
<
int
>
thresholds
=
read_line_to_array
<
int
>
();
cout
<<
"Number of lambdas: "
<<
lambdas
.
size
()
<<
endl
;
cout
<<
"Number of lambdas: "
<<
lambdas
.
size
()
<<
endl
;
cout
<<
"Number of Ps: "
<<
ps
.
size
()
<<
endl
;
cout
<<
"Number of Ps: "
<<
ps
.
size
()
<<
endl
;
cout
<<
"Number of thresholds: "
<<
thresholds
.
size
()
<<
endl
;
ofstream
RES
(
"simulation.res"
);
ofstream
RES
(
"simulation.res"
);
mutex
mut
;
mutex
mut
;
ProgressBar
progress_bar
(
lambdas
.
size
()
*
ps
.
size
()
*
REPEAT
);
ProgressBar
progress_bar
(
lambdas
.
size
()
*
ps
.
size
()
*
thresholds
.
size
()
*
REPEAT
);
progress_bar
.
set_desc
(
"Simulating"
);
progress_bar
.
set_desc
(
"Simulating"
);
progress_bar
.
start
();
progress_bar
.
start
();
for
(
auto
lambda
:
lambdas
)
{
for
(
auto
lambda
:
lambdas
)
{
for
(
auto
p
:
ps
)
{
for
(
auto
p
:
ps
)
{
task_queue
.
push_back
(
Task
(
lambda
,
p
)
);
for
(
auto
threshold
:
thresholds
)
{
task_queue
.
push_back
(
Task
(
lambda
,
p
,
threshold
)
);
}
}
}
}
}
vector
<
thread
>
thrs
;
vector
<
thread
>
thrs
;
for
(
int
i
=
0
;
i
<
THREAD_NUM
;
++
i
)
{
for
(
int
i
=
0
;
i
<
THREAD_NUM
;
++
i
)
{
thrs
.
push_back
(
thread
(
run_thread
,
ref
(
RES
),
ref
(
mut
),
ref
(
progress_bar
)
)
);
thrs
.
push_back
(
thread
(
run_thread
,
ref
(
RES
),
ref
(
mut
),
ref
(
progress_bar
)
)
);
task_queue
.
push_back
(
Task
(
-
1
,
0
)
);
task_queue
.
push_back
(
Task
(
-
1
,
0
,
0
)
);
}
}
for
(
auto
&
x
:
thrs
)
{
for
(
auto
&
x
:
thrs
)
{
x
.
join
();
x
.
join
();
...
...
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