Commit 96ec9f28 by Tianqi Yang

feat(markov): add supplement support in main

parent 27088796
...@@ -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 ) ) ) )
...@@ -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 ();
......
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