1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
| class AISimulationDirector: """ NVIDIA专利核心: AI仿真导演 AI模型接收上下文+历史,输出: 1. 资产下一步行动决策 2. 对应的仿真操作指令 这不是简单分类,而是生成性决策 """ def __init__(self, model_name="nvidia/llama-3.1-nemotron-70b"): self.model = model_name self.action_space = { "vehicle_actions": [ "accelerate", "brake", "turn_left", "turn_right", "change_lane", "stop", "reverse", "park" ], "pedestrian_actions": [ "walk_forward", "walk_back", "turn", "stop", "run", "cross_road", "enter_vehicle" ], "environment_actions": [ "change_weather", "change_light", "spawn_object", "remove_object", "trigger_event" ] } def decide_next_action(self, context, history): """ AI模型决策: 基于上下文和历史决定下一步行动 输入: 上下文数据 + 历史仿真数据 输出: 行动决策 + 仿真操作指令 """ prompt = self._build_prompt(context, history) decision = { "asset_id": "vehicle_1", "action": "emergency_brake", "reason": "pedestrian_1 entering road at 15m ahead", "simulation_ops": [ { "op": "set_velocity", "asset_id": "vehicle_1", "params": {"target_velocity": [0, 0, 0], "deceleration": 8.0} }, { "op": "set_animation", "asset_id": "pedestrian_1", "params": {"animation": "walking", "target_position": [12.0, 0, 0]} }, { "op": "trigger_event", "params": {"event": "near_miss", "severity": "high"} } ], "bounding_box_update": { "vehicle_1": [10.5, 2.0, 0.0, 4.5, 1.8, 1.5], "pedestrian_1": [12.0, 0.0, 0.0, 0.5, 0.5, 1.7] } } return decision def _build_prompt(self, context, history): """构建AI模型输入提示""" return f""" 你是一个仿真场景导演。基于当前场景状态和历史, 决定下一步应该发生什么行动。 当前场景: {context['scene']} 历史事件: {history['events'][-5:]} 所有物体边界框: {context['bounding_boxes']} 请输出JSON格式的行动决策。 """
|