# mpcRL **Repository Path**: nameiscs/mpcRL ## Basic Information - **Project Name**: mpcRL - **Description**: 将RL的值函数作为MPC的终端损失,从而将MPC与RL结合起来 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-11-18 - **Last Updated**: 2026-05-29 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README 该仓库为论文《[Reinforcement Learning-Based Model Predictive Control for Discrete-Time Systems](10.1109/TNNLS.2023.3273590)》的复现 在[config.py](mpcRL/config.py)文件中,设置一些参数 ``` # 预测时域 self.N = 3 self.system_type = 'Linear' # or 'Nonlinear' # 学习参数 self.learning_rate = 1e-6 self.epsilon = 1e-8 self.max_iterations = 100 # 值函数近似参数 self.poly_order = 3 self.num_samples = 9 # 采样数 self.sample_lb = [] # 采样上界 self.sample_ub = [] # 采样下界 # 求解器配置 self.solver_opts = { 'ipopt': { 'max_iter': 1000, 'print_level': 0, 'tol': 1e-4, 'acceptable_tol': 1e-2 }, 'print_time': False } self.solver = 'default' # or 'LQR' self.verbose = True self.Interrupt = False # 到达epsilon后是否中断 self.save = True # 保存日志(路径为data/) ``` 其中 * (1)self.sample_lb = [] 和 self.sample_ub = [] 分别设置采样空间 * (2)对于系统的约束条件,需要额外设置lb和ub ``` lb = np.array([-0.5, -0.5, -np.inf]) ub = np.array([3.5, 2.5, np.inf]) ``` 当变量没有约束时,设置为np.inf,在代码中就不会将其加入 * (3)self.solver = 'default' # or 'LQR',对于线性模型可以使用'LQR'进行求解,非线性模型只能用casadi求解 对于线性模型结果如下: 训练结果 ![](data/rlmpc_learning_linear.png) 仿真结果 ![](data/rlmpc_simulation_linear.png) 对于非线性模型结果如下: 训练结果 ![](data/rlmpc_learning_nonlinear.png) 仿真结果 ![](data/rlmpc_simulation_nonlinear.png) 这里也对使用人工设计终端损失进行对比 $$ cost = \sum^{N-1}_{i=0}x_i^TQx_i + u_i^TRu_i + x_N^TPx_N $$ 其中$P$为终端损失矩阵 对比如下: 线性模型 ![](data/rlmpc_handle_compare_LinearSystem.png) 非线性模型 ![](data/rlmpc_handle_compare_NonlinearSystem.png) 可以看出两者效果还是相近的,说明在无法人工设计终端损失时,可以用这种RL的值函数进行代替,效果也相近。