Once a trajectory has been built, the user can decide to optimize it, to reduce its lenght. The function int p3d_optim(p3d_trj *t, double *gain) optimize the trajectory t by dividing it randomly in three parts and replacing any of those parts that can be replaced by a valid local path. The gain of lenght obtained is returned.