create deepReinforcementLearning repo, test print vehicle

This commit is contained in:
2024-06-11 22:24:59 +02:00
parent 99e87a7b5b
commit fca991eb37
6 changed files with 1075 additions and 0 deletions
+88
View File
@@ -0,0 +1,88 @@
NAME_TEST=is_good
CC=gcc
ROOT_DIR=$(PWD)
YTESTDIR=$(PWD)/../../ytest_t
YTOOLDIR=$(PWD)/../../ytools_t
YPERMDIR=$(PWD)/../../ypermutation_t
DIMDIR=$(PWD)/../../dimension_t
TENSDIR=$(PWD)/../../tensor_t
NEURODIR=$(PWD)/../../neuron_t
INCLUDE_DIR=$(PWD)/../src/deepQlearning
CFLAGS=-I$(INCLUDE_DIR) -I$(NEURODIR)/src -I$(YPERMDIR)/src -I$(YTESTDIR)/include_ytest/include -I$(DIMDIR)/src -I$(TENSDIR)/src -I$(YTOOLDIR)/include #"-D DEBUG=1"
LDFLAGS=-L$(YTESTDIR) -lytest -lOpenCL -lm -lpthread #-lcurses
#SRC_DIR=$(ROOT_DIR)/src
#SRC=$(wildcard */*/*.c)
SRC=$(wildcard **/**/*.c)
#HEADS=$(OBJS:.o=.h)
TEST_DIR=$(PWD)
EXECSRC=$(NAME_TEST).c
#EXECSRC=openF.c
EXEC=launch_$(NAME_TEST)_m
NEUROSRC=$(NEURODIR)/src/neuron_t/neuron_t.c
NEUROSRC_O=$(NEUROSRC:.c=.o)
TENSRC=$(TENSDIR)/src/tensor_t/tensor_t.c
TENSRC_O=$(TENSRC:.c=.o)
VEHICLESRC=$(INCLUDE_DIR)/vehicle.c
VEHICLESRC_O=$(VEHICLESRC:.c=.o)
TOOLSRC_O=$(YTOOLDIR)/src/tools_t/tools_t.o
PERMSRC_O=$(YPERMDIR)/src/permutation_t/permutation_t.o
DIMSRC_O=$(DIMDIR)/src/dimension_t/dimension_t.o
TOPTARGETS := all clean
DEPS=$(DIMDIR) $(YPERMDIR) $(YTESTDIR) $(TENSDIR) $(NEURODIR) $(YTOOLDIR)
OBJ=$(VEHICLESRC_O) $(DIMSRC_O) $(PERMSRC_O) $(TENSRC_O) $(NEUROSRC_O) $(TOOLSRC_O)
LIB_YTEST=$(YTESTDIR)/libytest.so
$(TOPTARGETS): $(DEPS)
$(DEPS):
$(MAKE) -C $@ $(MAKECMDGOALS)
#PERMSRC_O=$(PERMSRC:.c=.o)
#SETTSRC_O=$(PWD)/../src/set_theoric_t/set_theoric_t.o
#SETTSRC_O=$(SETTSRC:.c=.o)
#TOOLSRC=$(TOOLDIR)/src/tools_t/tools_t.c
#TOOLSRC_O=$(TOOLSRC:.c=.o)
all: $(EXEC) $(LIB_YTEST)
$(EXEC): $(EXECSRC) $(OBJ)
$(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS)
$(VEHICLESRC_O): $(VEHICLESRC) $(TOOLSRC_O) $(DIMSRC_O)
$(CC) -o $@ -c $< $(CFLAGS)
.PHONY: clean mrproper
clean:
rm -f $(OBJ)
mrproper: clean
rm -f $(EXEC)
run: $(EXEC)
$(EXEC) -h
+210
View File
@@ -0,0 +1,210 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
// for sleep !
#ifdef __linux__
#include <unistd.h>
#elif _WIN32
#include <windows.h>
#endif
#include "ftest/ftest.h"
#include "ftest/ftest_array.h"
#include "fmock/fmock.h"
//#include "permutation_t/permutation_t.h"
#include "neuron_t/neuron_t.h"
#include "vehicle.h"
TEST(create_coordenate){
struct coordinate * coord = create_coordinate(3);
coord->x[0]=0;
coord->x[1]=1.2;
coord->x[0]=0.8;
free_coordinate(coord);
}
TEST(create_blocks){
size_t nb_block = 7;
size_t dim= 2;
struct blocks * zn = create_blocks(nb_block, dim);
for(size_t i=0; i<nb_block; ++i){
for(size_t j=0; j<dim; ++j){
zn->lower_bound_block[i]->x[j] = 0;
zn->upper_bound_block[i]->x[j] = (i+1)*(j+1);
}
}
for(size_t i=0; i<nb_block; ++i){
LOG("%s"," || (");
for(size_t j=0; j<dim; ++j)
LOG(" %f ", zn->lower_bound_block[i]->x[j]);
LOG("%s",")\\ (");
for(size_t j=0; j<dim; ++j)
LOG(" %f ", zn->upper_bound_block[i]->x[j]);
LOG("%s",")");
}
LOG("\n");
free_blocks(zn);
}
TEST(is_in_blocks){
size_t nb_block = 3;
size_t dim= 2;
struct blocks * zn = create_blocks(nb_block, dim);
copy_coordinate(zn->lower_bound_block[0], (float[]){0,0});
copy_coordinate(zn->upper_bound_block[0], (float[]){2,2});
copy_coordinate(zn->lower_bound_block[1], (float[]){2,0});
copy_coordinate(zn->upper_bound_block[1], (float[]){4,4});
copy_coordinate(zn->lower_bound_block[2], (float[]){0,4});
copy_coordinate(zn->upper_bound_block[2], (float[]){6,7});
struct coordinate *coord = create_coordinate(2);
copy_coordinate(coord, (float[]){1,1});
EXPECT_TRUE(is_in_blocks(zn, coord));
copy_coordinate(coord, (float[]){1,5});
EXPECT_TRUE(is_in_blocks(zn, coord));
copy_coordinate(coord, (float[]){3,3});
EXPECT_TRUE(is_in_blocks(zn, coord));
copy_coordinate(coord, (float[]){1,3});
EXPECT_FALSE(is_in_blocks(zn, coord));
print2D_blocks(zn,0.4,0.6, '.');
free_blocks(zn);
free_coordinate(coord);
}
TEST(print_blocks_withPoint){
size_t nb_block = 7;
size_t dim= 2;
struct blocks * zn = create_blocks(nb_block, dim);
/*
copy_coordinate(zn->lower_bound_block[0], (float[]){0,0});
copy_coordinate(zn->upper_bound_block[0], (float[]){8,2});
copy_coordinate(zn->lower_bound_block[1], (float[]){8,0});
copy_coordinate(zn->upper_bound_block[1], (float[]){12,4});
copy_coordinate(zn->lower_bound_block[2], (float[]){0,4});
copy_coordinate(zn->upper_bound_block[2], (float[]){14,7});
copy_coordinate(zn->lower_bound_block[3], (float[]){15,2});
copy_coordinate(zn->upper_bound_block[3], (float[]){18,7});
*/
copy_coordinate(zn->lower_bound_block[0], (float[]){0,0});
copy_coordinate(zn->upper_bound_block[0], (float[]){2,7});
copy_coordinate(zn->lower_bound_block[1], (float[]){2,0});
copy_coordinate(zn->upper_bound_block[1], (float[]){4,2});
copy_coordinate(zn->lower_bound_block[2], (float[]){4,1});
copy_coordinate(zn->upper_bound_block[2], (float[]){8,3});
copy_coordinate(zn->lower_bound_block[3], (float[]){8,0});
copy_coordinate(zn->upper_bound_block[3], (float[]){16,2});
copy_coordinate(zn->lower_bound_block[4], (float[]){16,0});
copy_coordinate(zn->upper_bound_block[4], (float[]){18,7});
copy_coordinate(zn->lower_bound_block[5], (float[]){6,7});
copy_coordinate(zn->upper_bound_block[5], (float[]){18,9});
copy_coordinate(zn->lower_bound_block[6], (float[]){2,6});
copy_coordinate(zn->upper_bound_block[6], (float[]){6,8});
struct coordinate *coord = create_coordinate(2);
copy_coordinate(coord, (float[]){1,1});
EXPECT_TRUE(is_in_blocks(zn, coord));
print2D_blocks_withPoint(zn,0.24,0.48, '#',coord);
//print2D_blocks(zn,0.14,0.28, '#');
copy_coordinate(coord, (float[]){1,5});
EXPECT_TRUE(is_in_blocks(zn, coord));
// print2D_blocks_withPoint(zn,0.24,0.48, '#',coord);
copy_coordinate(coord, (float[]){2,3});
EXPECT_TRUE(is_in_blocks(zn, coord));
// print2D_blocks_withPoint(zn,0.24,0.48, '#',coord);
copy_coordinate(coord, (float[]){7,5});
EXPECT_FALSE(is_in_blocks(zn, coord));
free_blocks(zn);
free_coordinate(coord);
}
TEST(first_vehicle){
size_t nb_block = 7;
size_t dim= 2;
struct blocks * path = create_blocks(nb_block, dim);
copy_coordinate(path->lower_bound_block[0], (float[]){0,0});
copy_coordinate(path->upper_bound_block[0], (float[]){2,7});
copy_coordinate(path->lower_bound_block[1], (float[]){2,0});
copy_coordinate(path->upper_bound_block[1], (float[]){4,2});
copy_coordinate(path->lower_bound_block[2], (float[]){4,1});
copy_coordinate(path->upper_bound_block[2], (float[]){8,3});
copy_coordinate(path->lower_bound_block[3], (float[]){8,0});
copy_coordinate(path->upper_bound_block[3], (float[]){16,2});
copy_coordinate(path->lower_bound_block[4], (float[]){16,0});
copy_coordinate(path->upper_bound_block[4], (float[]){18,7});
copy_coordinate(path->lower_bound_block[5], (float[]){6,7});
copy_coordinate(path->upper_bound_block[5], (float[]){18,9});
copy_coordinate(path->lower_bound_block[6], (float[]){2,6});
copy_coordinate(path->upper_bound_block[6], (float[]){6,8});
update_bounds_limits_blocks(path);
struct vehicle *vhcl = create_vehicle(path);
print_vehicle_n_path(vhcl, 0.2,0.4);
step(vhcl, CENTER);
sleep(2);
print_vehicle_n_path(vhcl, 0.2,0.4);
step(vhcl, CENTER);
sleep(2);
print_vehicle_n_path(vhcl, 0.2,0.4);
step(vhcl, CENTER);
sleep(2);
print_vehicle_n_path(vhcl, 0.2,0.4);
step(vhcl, CENTER);
sleep(2);
print_vehicle_n_path(vhcl, 0.2,0.4);
free_vehicle(vhcl);
}
int main(int argc, char **argv){
run_all_tests_args(argc, argv);
return 0;
}