y_nnn : change learn_to_drive and add some bash print
This commit is contained in:
@@ -4,10 +4,26 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "learn_to_drive.h"
|
||||
|
||||
#include "y_net_neur_net/y_nnn_screen_manager.h"
|
||||
|
||||
#include "y_socket_t/y_socket_t.h"
|
||||
|
||||
void y_nnn_manager_handle_input(char * buf, int len_buf, void *arg);
|
||||
|
||||
struct arg_run_qlearn_bprint{
|
||||
struct arg_bash *bash_arg;
|
||||
struct RL_agent *rlAgent;
|
||||
};
|
||||
|
||||
struct arg_run_qlearn_bprint * create_arg_run_qlearn_bprint(
|
||||
struct arg_bash *bash_arg,
|
||||
struct RL_agent *rlAgent
|
||||
);
|
||||
|
||||
void free_arg_run_qlearn_bprint(struct arg_run_qlearn_bprint *arg);
|
||||
|
||||
void* runBashPrint(void *arg);
|
||||
|
||||
#endif /* Y_NETWORK_NEURAL_NETWORK__MANAGER__H_C */
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
#include "list_t/list_t.h"
|
||||
|
||||
#include "vehicle.h"
|
||||
|
||||
GENERATE_LIST_ALL(pid_t)
|
||||
|
||||
#define SIZE_LOCAL_BUF 300
|
||||
@@ -23,6 +25,16 @@ GENERATE_LIST_ALL(pid_t)
|
||||
#define GOTO_TOP_LEFT "\x1B[0;0f"
|
||||
#define LEN_GOTO_TOP_LEFT 6
|
||||
|
||||
#define BASH_WRITE_IF_EXIST(bash,buf,len_buf) \
|
||||
do{\
|
||||
if(bash_arg->fd_new_bash_pid>0){\
|
||||
write(bash_arg->fd_new_bash_pid, buf, len_buf);\
|
||||
}\
|
||||
if(bash_arg->fd_current_bash_pid>0){\
|
||||
write(bash_arg->fd_current_bash_pid, buf, len_buf);\
|
||||
}\
|
||||
} while(0);
|
||||
|
||||
//#include "y_socket_t/y_list_var_tool.h"
|
||||
|
||||
pid_t pidof(char *target, struct main_list_pid_t *m_pid_t);
|
||||
@@ -56,6 +68,7 @@ void free_arg_bash(struct arg_bash *arg);
|
||||
|
||||
int write_duplicate_bash(int fd, char *content, size_t size_content);
|
||||
|
||||
int new_bash_exist(struct arg_bash *bash_arg);
|
||||
|
||||
void* run_newbash(void *arg);
|
||||
void* wait_newbash(void *arg);
|
||||
@@ -69,4 +82,8 @@ void* launch_new_bash(void *arg);
|
||||
void* launch_wait_bash(void *arg);
|
||||
void* launch_sleep_wait_bash(void *arg);
|
||||
|
||||
void bash_print_vehicle_n_path(struct vehicle *v, float scale_x, float scale_y, struct arg_bash *bash_arg);
|
||||
void bash_print2D_blocks_indexOne_withPoint(struct blocks *blk, float scale_x, float scale_y, coordinate *coordPoint, struct arg_bash *bash_arg);
|
||||
|
||||
|
||||
#endif /* Y_NETWORK_NEURAL_NETWORK__SCREEN_MANAGER__H_C */
|
||||
|
||||
@@ -2,18 +2,36 @@
|
||||
|
||||
#include "y_net_neur_net/y_nnn_manager.h"
|
||||
|
||||
struct arg_run_qlearn_bprint * create_arg_run_qlearn_bprint(
|
||||
struct arg_bash *bash_arg,
|
||||
struct RL_agent *rlAgent
|
||||
){
|
||||
struct arg_run_qlearn_bprint *r_arg=malloc(sizeof(struct arg_run_qlearn_bprint));
|
||||
r_arg->bash_arg = bash_arg;
|
||||
r_arg->rlAgent = rlAgent;
|
||||
|
||||
return r_arg;
|
||||
}
|
||||
|
||||
void free_arg_run_qlearn_bprint(struct arg_run_qlearn_bprint *arg){
|
||||
free_RL_agent(arg->rlAgent);
|
||||
free_arg_bash(arg->bash_arg);
|
||||
free(arg);
|
||||
}
|
||||
|
||||
void y_nnn_manager_handle_input(char * buf, int len_buf, void *arg){
|
||||
//struct arg_bash *bash_arg=(struct arg_bash*)arg;
|
||||
struct arg_run_qlearn_bprint *run_arg=(struct arg_run_bash_print*)arg;
|
||||
struct arg_bash *bash_arg=run_arg->bash_arg;
|
||||
|
||||
if(arg && (len_buf>0)){
|
||||
|
||||
printf("debug: %s #%d (%d)\n",buf,len_buf,((struct arg_bash*)arg)->old_bash_pid);
|
||||
printf("debug: %s #%d (%d)\n",buf,len_buf,(bash_arg)->old_bash_pid);
|
||||
if(strncmp(buf,"newbash",7)==0){
|
||||
run_newbash(arg);
|
||||
run_newbash(bash_arg);
|
||||
}else if(strncmp(buf,"waitbash",8)==0){
|
||||
launch_sleep_wait_bash(arg);
|
||||
launch_sleep_wait_bash(bash_arg);
|
||||
}else if(strncmp(buf,"killbash",8)==0){
|
||||
kill_all_bash(arg);
|
||||
kill_all_bash(bash_arg);
|
||||
}else{
|
||||
printf("debug: %s is not handle\n",buf);
|
||||
}
|
||||
@@ -22,3 +40,69 @@ void y_nnn_manager_handle_input(char * buf, int len_buf, void *arg){
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void* runBashPrint(void *arg){
|
||||
struct arg_run_bash_print *arg_run=(struct arg_run_bash_print*)arg;
|
||||
struct RL_agent *rlAgent = arg_run->rlAgent;
|
||||
struct arg_bash *bash_arg = arg_run->bash_arg;
|
||||
|
||||
struct status_qlearning *qlStatus = rlAgent->status;
|
||||
struct print_params * pprint = rlAgent->pprint;
|
||||
struct vehicle *car = rlAgent->car;
|
||||
size_t count_print = 0;
|
||||
char buf[SIZE_LOCAL_BUF];
|
||||
int len_buf;
|
||||
while((new_bash_exist(bash_arg)) && check_go_on_print_params(pprint) && !is_ending(qlStatus)){
|
||||
if(/*(qlStatus->nb_episodes %125 == 0) &&*/ pprint->printed){
|
||||
//pthread_mutex_lock(&(pprint->mut_printed));
|
||||
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)
|
||||
|
||||
////printf("ep: %ld\n",qlStatus->index_episode);
|
||||
len_buf=sprintf(buf,"ep: %ld\n",qlStatus->index_episode);
|
||||
BASH_WRITE_IF_EXIST(bash_arg, buf, len_buf)
|
||||
neurons_TYPE_FLOAT * net_main = rlAgent->networks->main_net;
|
||||
neurons_TYPE_FLOAT * net_target = rlAgent->networks->target_net;
|
||||
for(size_t i=0; (i<net_main->output->dim->rank) && (new_bash_exist(bash_arg)); ++i) {
|
||||
////printf("{sensro[%s]:%f "" vs oldsens[%s]: %f}\n",action_name[i%COUNT_ACTION],net_target->output->x[i],
|
||||
len_buf = sprintf(buf,"{sensro[%s]:%f "" vs oldsens[%s]: %f}\n",action_name[i%COUNT_ACTION],net_target->output->x[i],action_name[i%COUNT_ACTION],net_main->output->x[i]);
|
||||
BASH_WRITE_IF_EXIST(bash_arg, buf, len_buf)
|
||||
|
||||
}
|
||||
////printf("\n< %5.2f > ( %s ) \n", car->direction, action_name[qlStatus->action % COUNT_ACTION]);
|
||||
len_buf=sprintf(buf,"\n< %5.2f > ( %s ) \n", car->direction, action_name[qlStatus->action % COUNT_ACTION]);
|
||||
BASH_WRITE_IF_EXIST(bash_arg, buf, len_buf)
|
||||
//print_weight_in_neurons_TYPE_FLOAT(net_main, "net_main_wei");
|
||||
//PRINT_ATTRIBUTE_TENS_IN_ALL_LAYERS(TYPE_FLOAT, net_main, weight_in, "net_main_we_in");
|
||||
///PRINT_ATTRIBUTE_TENS_IN_ALL_LAYERS(TYPE_FLOAT, net_main, output, "net_main_out");
|
||||
//PRINT_ATTRIBUTE_TENS_IN_ALL_LAYERS(TYPE_FLOAT, net_target, output, "net_target_out");
|
||||
//PRINT_ATTRIBUTE_TENS_IN_ALL_LAYERS(TYPE_FLOAT, net_main, input, "net_main_input");
|
||||
////printf(" action : %d , factor : %f nb_episodes : %ld \n",qlStatus->action,rlAgent->qlearnParams->exploration_factor, rlAgent->status->nb_episodes);
|
||||
len_buf=sprintf(buf," action : %d , factor : %f nb_episodes : %ld \n",qlStatus->action,rlAgent->qlearnParams->exploration_factor, rlAgent->status->nb_episodes);
|
||||
BASH_WRITE_IF_EXIST(bash_arg, buf, len_buf)
|
||||
|
||||
FOR_LIST_FORM_BEGIN(TYPE_L_INT, qlStatus->progress_best_cumul){
|
||||
////printf(" | %ld |,",(qlStatus->progress_best_cumul)->current_list->value);
|
||||
len_buf=sprintf(buf," | %ld |,",(qlStatus->progress_best_cumul)->current_list->value);
|
||||
BASH_WRITE_IF_EXIST(bash_arg, buf, len_buf)
|
||||
}
|
||||
////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)
|
||||
|
||||
}
|
||||
Sleep(pprint->delay->delay_between_games);
|
||||
++count_print;
|
||||
if(count_print > 20){
|
||||
count_print = 0;
|
||||
clear_screen();
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -133,6 +133,10 @@ void free_arg_bash(struct arg_bash *arg){
|
||||
free(arg);
|
||||
}
|
||||
|
||||
int new_bash_exist(struct arg_bash *bash_arg){
|
||||
return ((bash_arg->fd_new_bash_pid>0) || (bash_arg->fd_current_bash_pid));
|
||||
}
|
||||
|
||||
/* run new bash terminal graphic, can be called directly or in a thread */
|
||||
void* run_newbash(void* argg){
|
||||
struct arg_bash *arg=(struct arg_bash*)argg;
|
||||
@@ -339,4 +343,89 @@ void* launch_wait_bash(void *b_arg){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#define __BASH_WRITE_IF_EXIST(bash_arg, buf, len_buf)\
|
||||
if(bash_arg->fd_new_bash_pid>0){\
|
||||
write(bash_arg->fd_new_bash_pid, buf , len_buf);\
|
||||
}\
|
||||
if(bash_arg->fd_current_bash_pid>0){\
|
||||
write(bash_arg->fd_current_bash_pid, buf, len_buf);\
|
||||
}\
|
||||
|
||||
|
||||
void bash_print_vehicle_n_path(struct vehicle *v, float scale_x, float scale_y, struct arg_bash *bash_arg){
|
||||
static bool first = true;
|
||||
if(first){
|
||||
first = false;
|
||||
init_win();
|
||||
char pad[w.ws_col+1];
|
||||
int i=0;
|
||||
for(i=0; i<w.ws_col+1; ++i) pad[i]=' ';
|
||||
pad[i]='\0';
|
||||
for(i=0; i<w.ws_row / 2 ; ++i) printf("%s\n",pad);;
|
||||
|
||||
}
|
||||
//goto_xy(0,w.ws_row - lines);
|
||||
////goto_xy(0,0);
|
||||
BASH_WRITE_IF_EXIST(bash_arg, GOTO_TOP_LEFT, LEN_GOTO_TOP_LEFT);
|
||||
//printf("lines : %d , row : %d : diff: %d\n",lines, w.ws_row , w.ws_row - lines);
|
||||
bash_print2D_blocks_indexOne_withPoint(v->path, scale_x, scale_y, v->coord, bash_arg);
|
||||
//printf("lines print : %d\n",lines);
|
||||
char loggg[SIZE_LOCAL_BUF];
|
||||
int len_loggg=sprintf(loggg,"\nlog : %s \n",v->status->log);
|
||||
BASH_WRITE_IF_EXIST(bash_arg, loggg, len_loggg);
|
||||
}
|
||||
|
||||
|
||||
void bash_print2D_blocks_indexOne_withPoint(struct blocks *blk, float scale_x, float scale_y, coordinate *coordPoint, struct arg_bash *bash_arg){
|
||||
if(blk->dimension_size == 2){
|
||||
update_bounds_limits_blocks(blk);
|
||||
coordinate ** bounds_coord = blk->bounds_all_blocks;
|
||||
|
||||
coordinate * coord = create_coordinate(2);
|
||||
|
||||
float *radius = malloc(2 * sizeof(float));
|
||||
radius[0]=scale_x;
|
||||
radius[1]=scale_y;
|
||||
char buf[SIZE_LOCAL_BUF];
|
||||
int len_buf;
|
||||
struct blocks * blk_point = block_neighbord_Point(coordPoint, radius);
|
||||
for(coord->x[1] = bounds_coord[1]->x[1]; coord->x[1] > bounds_coord[0]->x[1]; coord->x[1]-=scale_y ){
|
||||
for(coord->x[0] = bounds_coord[0]->x[0]; coord->x[0] < bounds_coord[1]->x[0]; coord->x[0]+=scale_x ){
|
||||
if(is_in_blocks(blk_point, coord)){
|
||||
////printf("\033[0;31m"); // red
|
||||
BASH_WRITE_IF_EXIST(bash_arg, "\033[0;31m", 7);
|
||||
}
|
||||
int in = is_in_blocks(blk,coord);
|
||||
if(in){
|
||||
if(in>9){
|
||||
int div=in%10;
|
||||
////printf("%d",div);
|
||||
len_buf=sprintf(buf,"%d",div);
|
||||
BASH_WRITE_IF_EXIST(bash_arg, buf, len_buf);
|
||||
}else{
|
||||
////printf("%d",in);
|
||||
len_buf=sprintf(buf,"%d",in);
|
||||
BASH_WRITE_IF_EXIST(bash_arg, buf, len_buf);
|
||||
}
|
||||
}else{
|
||||
////printf("."); //printf(" ");
|
||||
BASH_WRITE_IF_EXIST(bash_arg, ".", 1);
|
||||
}
|
||||
|
||||
////printf("\033[0;37m"); // white
|
||||
BASH_WRITE_IF_EXIST(bash_arg, "\033[0;37m", 7); // white
|
||||
}
|
||||
///printf("\n");
|
||||
BASH_WRITE_IF_EXIST(bash_arg,"\n",1);
|
||||
}
|
||||
|
||||
|
||||
free_coordinate(coord);
|
||||
|
||||
free_blocks(blk_point);
|
||||
free(radius);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -215,6 +215,7 @@ void *func_bash(void* b_arg){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if 0
|
||||
TEST(try_y_socket_manager){
|
||||
struct arg_bash *bash_arg= create_arg_bash();
|
||||
struct arg_var_ * var = create_arg_var_(y_nnn_manager_handle_input, bash_arg);
|
||||
@@ -239,6 +240,7 @@ TEST(try_y_socket_manager){
|
||||
free_arg_bash(bash_arg);
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
int main(int argc, char **argv){
|
||||
|
||||
|
||||
Reference in New Issue
Block a user