Learning-Based UAV Trajectory Optimization with Collision Avoidance and Connectivity Constraints