Reinforcement Learning based Algorithm with Safety Handling and Risk Perception