diff --git a/y_network_neural_network_/include/y_net_neur_net/y_nnn_screen_manager.h b/y_network_neural_network_/include/y_net_neur_net/y_nnn_screen_manager.h index 0d8e16f..c1fccaf 100644 --- a/y_network_neural_network_/include/y_net_neur_net/y_nnn_screen_manager.h +++ b/y_network_neural_network_/include/y_net_neur_net/y_nnn_screen_manager.h @@ -53,6 +53,8 @@ struct arg_bash{ int fd_current_bash_pid; pthread_t *thread_launch; + pthread_t *thread_run_newbash; + pthread_t *thread_run_waitbash; pthread_mutex_t *mut_bash_var; pthread_cond_t *cond_bash_var; diff --git a/y_network_neural_network_/src/y_net_neur_net/y_nnn_manager.c b/y_network_neural_network_/src/y_net_neur_net/y_nnn_manager.c index eb5a904..d96d683 100644 --- a/y_network_neural_network_/src/y_net_neur_net/y_nnn_manager.c +++ b/y_network_neural_network_/src/y_net_neur_net/y_nnn_manager.c @@ -43,14 +43,17 @@ void y_nnn_manager_handle_input(char * buf, int len_buf, void *arg){ kill_all_bash(bash_arg); }else if(strncmp(buf,"startprintnewbash",17)==0){ run_newbash(bash_arg); - pthread_t thread_run; - pthread_create(&thread_run, NULL, runBashPrint, arg); + bash_arg->thread_run_newbash=malloc(sizeof(pthread_t)); + pthread_create(bash_arg->thread_run_newbash, NULL, runBashPrint, arg); + //pthread_t thread_run; + //pthread_create(&thread_run, NULL, runBashPrint, arg); //Sleep(2); }else if(strncmp(buf,"startprintwaitbash",18)==0){ - - pthread_t thread_run; - pthread_create(&thread_run, NULL, run_sleep_wait_bash_and_print, arg); + bash_arg->thread_run_waitbash=malloc(sizeof(pthread_t)); + pthread_create(bash_arg->thread_run_waitbash, NULL, run_sleep_wait_bash_and_print, arg); + //pthread_t thread_run; + //pthread_create(&thread_run, NULL, run_sleep_wait_bash_and_print, arg); }else if(strncmp(buf,"stopprintbash",13)==0){ pthread_mutex_lock(bash_arg->mut_bash_var); @@ -106,11 +109,12 @@ void* runBashPrint(void *arg){ pthread_mutex_lock(&(car->mut_coord)); bash_print_vehicle_n_path(car, pprint->scale_x, pprint->scale_y,bash_arg); pthread_mutex_unlock(&(car->mut_coord)); + //pthread_mutex_unlock(&(pprint->mut_printed)); ////printf("%s ",pprint->string_space); len_buf=sprintf(buf,"%s ",pprint->string_space); BASH_WRITE_IF_EXIST(bash_arg, buf, len_buf) - +#if 0 ////printf("ep: %ld ",qlStatus->index_episode); len_buf=sprintf(buf,"ep: %ld\n",qlStatus->index_episode); BASH_WRITE_IF_EXIST(bash_arg, buf, len_buf) @@ -142,13 +146,15 @@ void* runBashPrint(void *arg){ ////printf("[%ld] %s ", rlAgent->car->status->cumulative_reward, pprint->string_space); len_buf=sprintf(buf,"[%ld] %s ", rlAgent->car->status->cumulative_reward, pprint->string_space); BASH_WRITE_IF_EXIST(bash_arg, buf, len_buf) - +#endif } Sleep(pprint->delay->delay_between_games); ++count_print; if(count_print > 20){ count_print = 0; - clear_screen(); + ////clear_screen(); + len_buf=sprintf(buf,"\e[2J\e[H"); + BASH_WRITE_IF_EXIST(bash_arg, buf, len_buf) } } printf("debug: end runBashPrint\n"); diff --git a/y_network_neural_network_/src/y_net_neur_net/y_nnn_screen_manager.c b/y_network_neural_network_/src/y_net_neur_net/y_nnn_screen_manager.c index 1d21608..a12463f 100644 --- a/y_network_neural_network_/src/y_net_neur_net/y_nnn_screen_manager.c +++ b/y_network_neural_network_/src/y_net_neur_net/y_nnn_screen_manager.c @@ -111,6 +111,9 @@ struct arg_bash *create_arg_bash(){ b_arg->go_on=1; b_arg->thread_launch=NULL; + b_arg->thread_run_newbash=NULL; + b_arg->thread_run_waitbash=NULL; + return b_arg; } @@ -136,7 +139,21 @@ void free_arg_bash(struct arg_bash *arg){ free(arg->thread_launch); } + if(arg->thread_launch){ + pthread_join(*(arg->thread_launch),NULL); + free(arg->thread_launch); + } + if(arg->thread_run_newbash){ + pthread_join(*(arg->thread_run_newbash),NULL); + free(arg->thread_run_newbash); + } + if(arg->thread_run_waitbash){ + pthread_join(*(arg->thread_run_waitbash),NULL); + free(arg->thread_run_waitbash); + } + free(arg); + } int new_bash_exist(struct arg_bash *bash_arg){ @@ -151,27 +168,31 @@ void* run_newbash(void* argg){ if(arg->new_bash_pid == arg->old_bash_pid){ pid_t pid=fork(); if(pid<0){ - perror("fork"); + ////perror("fork run_newbash"); + fprintf(stderr, "fork run_newbash error\n"); } else if(pid==0){/* child */ + usleep(200000); char *cmdbash[]={"/usr/bin/gnome-terminal",NULL}; execvp(cmdbash[0], cmdbash); + //printf("debug: new terminal created\n"); + arg->new_bash_pid = pidof("bash",NULL); }else{ wait(NULL); - usleep(20000); + //usleep(200000); pthread_mutex_lock(arg->mut_bash_var); - arg->new_bash_pid = pidof("bash",NULL); - arg->fd_new_bash_pid = open_duplicate_bash(arg->new_bash_pid); while(arg->new_bash_pid == arg->old_bash_pid) { - printf("debug: create new terminal: %d vs %d\n",arg->new_bash_pid,arg->old_bash_pid); - getchar(); - arg->new_bash_pid = pidof("bash",NULL); - arg->fd_new_bash_pid = open_duplicate_bash(arg->new_bash_pid); - //usleep(2000); + arg->new_bash_pid = pidof("bash",NULL); + printf("debug: create new terminal: %d vs %d: forkpid=%d\n",arg->new_bash_pid,arg->old_bash_pid,pid); + //getchar(); + //arg->new_bash_pid = pidof("bash",NULL); + //arg->fd_new_bash_pid = open_duplicate_bash(arg->new_bash_pid); + usleep(2000000); } + arg->fd_new_bash_pid = open_duplicate_bash(arg->new_bash_pid); pthread_mutex_unlock(arg->mut_bash_var); pthread_cond_signal(arg->cond_bash_var); @@ -198,6 +219,22 @@ void kill_all_bash(struct arg_bash *arg){ arg->fd_current_bash_pid=-1; } pthread_mutex_unlock(arg->mut_bash_var); + if(arg->thread_run_newbash){ + pthread_join(*(arg->thread_run_newbash),NULL); + free(arg->thread_run_newbash); + arg->thread_run_newbash=NULL; + } + if(arg->thread_run_waitbash){ + pthread_join(*(arg->thread_run_waitbash),NULL); + free(arg->thread_run_waitbash); + arg->thread_run_waitbash=NULL; + } + if(arg->thread_launch){ + pthread_join(*(arg->thread_launch),NULL); + free(arg->thread_launch); + arg->thread_launch=NULL; + } + } int check_go_on_bash(struct arg_bash *arg){ @@ -376,7 +413,10 @@ void bash_print_vehicle_n_path(struct vehicle *v, float scale_x, float scale_y, int i=0; for(i=0; ilower_bound_block[4], (float[]){0,0}); - copy_coordinate(path->upper_bound_block[4], (float[]){150,250}); - copy_coordinate(path->lower_bound_block[3], (float[]){150,40}); - copy_coordinate(path->upper_bound_block[3], (float[]){250,150}); - copy_coordinate(path->lower_bound_block[2], (float[]){250,80}); - copy_coordinate(path->upper_bound_block[2], (float[]){360,200}); - copy_coordinate(path->lower_bound_block[1], (float[]){360,70}); - copy_coordinate(path->upper_bound_block[1], (float[]){600,150}); - copy_coordinate(path->lower_bound_block[0], (float[]){600,90}); - copy_coordinate(path->upper_bound_block[0], (float[]){760,300}); - copy_coordinate(path->lower_bound_block[6], (float[]){260,300}); - copy_coordinate(path->upper_bound_block[6], (float[]){760,360}); - copy_coordinate(path->lower_bound_block[5], (float[]){0,250}); - copy_coordinate(path->upper_bound_block[5], (float[]){410,300}); - - - copy_coordinate(path->lower_bound_block[0], (float[]){0,0}); - copy_coordinate(path->upper_bound_block[0], (float[]){100,250}); - copy_coordinate(path->lower_bound_block[1], (float[]){100,0}); - copy_coordinate(path->upper_bound_block[1], (float[]){250,80}); - copy_coordinate(path->lower_bound_block[2], (float[]){250,0}); - copy_coordinate(path->upper_bound_block[2], (float[]){360,140}); - copy_coordinate(path->lower_bound_block[3], (float[]){360,70}); - copy_coordinate(path->upper_bound_block[3], (float[]){600,140}); - copy_coordinate(path->lower_bound_block[4], (float[]){600,90}); - copy_coordinate(path->upper_bound_block[4], (float[]){720,300}); - copy_coordinate(path->lower_bound_block[5], (float[]){300,300}); - copy_coordinate(path->upper_bound_block[5], (float[]){720,350}); - copy_coordinate(path->lower_bound_block[6], (float[]){0,250}); - copy_coordinate(path->upper_bound_block[6], (float[]){410,300}); - - - - - copy_coordinate(path->lower_bound_block[0], (float[]){0,300}); - copy_coordinate(path->upper_bound_block[0], (float[]){400,700}); - copy_coordinate(path->lower_bound_block[1], (float[]){100,0}); - copy_coordinate(path->upper_bound_block[1], (float[]){1000,300}); - copy_coordinate(path->lower_bound_block[2], (float[]){1000,50}); - copy_coordinate(path->upper_bound_block[2], (float[]){1400,500}); - copy_coordinate(path->lower_bound_block[3], (float[]){1400,200}); - copy_coordinate(path->upper_bound_block[3], (float[]){1800,700}); - copy_coordinate(path->lower_bound_block[4], (float[]){1100,700}); - copy_coordinate(path->upper_bound_block[4], (float[]){1700,1000}); - copy_coordinate(path->lower_bound_block[5], (float[]){800,600}); - copy_coordinate(path->upper_bound_block[5], (float[]){1100,975}); - copy_coordinate(path->lower_bound_block[6], (float[]){100,700}); - copy_coordinate(path->upper_bound_block[6], (float[]){800,975}); - */ #else @@ -415,7 +364,8 @@ struct status_qlearning *qlstatus = create_status_qlearning (); 20/*long int nb_training_before_update_weight_in_target*/, 10000/*size_t number_episodes*/ ); -/* UPDATE_ATTRIBUTE_NEURONE_IN_ALL_LAYERS(TYPE_FLOAT, nnetworks->main_net, d_f_act , df ); +/* + UPDATE_ATTRIBUTE_NEURONE_IN_ALL_LAYERS(TYPE_FLOAT, nnetworks->main_net, d_f_act , df ); UPDATE_ATTRIBUTE_NEURONE_IN_ALL_LAYERS(TYPE_FLOAT, nnetworks->main_net, f_act, f ); UPDATE_ATTRIBUTE_NEURONE_IN_ALL_LAYERS(TYPE_FLOAT, nnetworks->target_net, d_f_act , df ); UPDATE_ATTRIBUTE_NEURONE_IN_ALL_LAYERS(TYPE_FLOAT, nnetworks->target_net, f_act , f ); @@ -432,13 +382,18 @@ struct status_qlearning *qlstatus = create_status_qlearning (); pprint /*struct print_params * pprint*/, qlparams/*struct qlearning_params *qlearnParams*/ ); - - struct arg_bash *bash_arg= create_arg_bash(); + + pthread_t thread_learn; + pthread_create(&thread_learn, NULL, learn_to_drive, (void*)rlAgent); + //learn_to_drive(rlAgent); + + struct arg_bash *bash_arg= create_arg_bash(); struct arg_run_qlearn_bprint *argQL_BP = create_arg_run_qlearn_bprint(bash_arg, rlAgent); struct arg_var_ * var = create_arg_var_(y_nnn_manager_handle_input, argQL_BP); struct y_socket_t *argS = y_socket_create("1600", 2, 3, var); + pthread_t pollTh; pthread_create(&pollTh, NULL, y_socket_poll_fds, (void*)argS); @@ -446,11 +401,11 @@ struct status_qlearning *qlstatus = create_status_qlearning (); - learn_to_drive(rlAgent); pthread_join(pollTh, NULL); + pthread_join(thread_learn, NULL); y_socket_free(argS); free_arg_var_(var); diff --git a/ytest_t/libytest.so b/ytest_t/libytest.so index b0f16d5..c80ffed 100755 Binary files a/ytest_t/libytest.so and b/ytest_t/libytest.so differ