You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修复GLPK的‘missing variable name CPLEX LP文件处理错误’

GLPK求解PuLP动态模型时出现missing variable name CPLEX LP file processing error错误

我有一个动态规划模型,想用GLPK求解器运行,但遇到missing variable name CPLEX LP file processing error错误。之前还遇到过指向不同代码行的类似错误(更新前是第1947行,现在对应第1913行)。该模型在CBC求解器中能正常运行,且已验证GLPK和PuLP在其他类似问题中工作正常。

完整报错信息

Traceback (most recent call last):

  Cell In[12], line 1
    result = prob.solve(GLPK(options = ['--ranges', 'sensitivity.txt']))

  File C:\ProgramData\Anaconda3\lib\site-packages\pulp\pulp.py:1913 in solve
    status = solver.actualSolve(self, **kwargs)

  File C:\ProgramData\Anaconda3\lib\site-packages\pulp\apis\glpk_api.py:115 in actualSolve
    raise PulpSolverError("PuLP: Error while executing " + self.path)

PulpSolverError: PuLP: Error while executing glpsol.exe

GLPSOL: GLPK LP/MIP Solver, v4.65
Parameter(s) specified in the command line:
 --cpxlp C:\Users\TRISSD~1\AppData\Local\Temp\e22c89d89a96466681a5fabbb45117b5-pulp.lp
 -o C:\Users\TRISSD~1\AppData\Local\Temp\e22c89d89a96466681a5fabbb45117b5-pulp.sol
 --ranges sensitivity.txt
Reading problem data from 'C:\Users\TRISSD~1\AppData\Local\Temp\e22c89d89a96466681a5fabbb45117b5-pulp.lp'...
C:\Users\TRISSD~1\AppData\Local\Temp\e22c89d89a96466681a5fabbb45117b5-pulp.lp:3: missing variable name
CPLEX LP file processing error

设置msg=1后的报错

Traceback (most recent call last):

  Cell In[17], line 1
    result = prob.solve(GLPK(msg=1))#(options = ['--ranges', 'sensitivity.txt']))

  File C:\ProgramData\Anaconda3\lib\site-packages\pulp\pulp.py:1913 in solve
    status = solver.actualSolve(self, **kwargs)

  File C:\ProgramData\Anaconda3\lib\site-packages\pulp\apis\glpk_api.py:115 in actualSolve
    raise PulpSolverError("PuLP: Error while executing " + self.path)

PulpSolverError: PuLP: Error while executing glpsol.exe

GLPSOL: GLPK LP/MIP Solver, v4.65
Parameter(s) specified in the command line:
 --cpxlp C:\Users\TRISSD~1\AppData\Local\Temp\95d05ec9f5ae43d4906085fc8664b88d-pulp.lp
 -o C:\Users\TRISSD~1\AppData\Local\Temp\95d05ec9f5ae43d4906085fc8664b88d-pulp.sol
Reading problem data from 'C:\Users\TRISSD~1\AppData\Local\Temp\95d05ec9f5ae43d4906085fc8664b88d-pulp.lp'...
C:\Users\TRISSD~1\AppData\Local\Temp\95d05ec9f5ae43d4906085fc8664b88d-pulp.lp:3: missing variable name
CPLEX LP file processing error

环境配置

  • Windows 10
  • Python 3.8.16
  • Spyder 5.4.3
  • PuLP 2.7.0
  • GLPK 4.65

问题代码

# Import Libraries

import pulp
from pulp import GLPK

prob = pulp.LpProblem('Dynamic_Problem_Continuous_Var', pulp.LpMinimize)

x1 = pulp.LpVariable('1Jan', lowBound = 2000, upBound = 4000)
x2 = pulp.LpVariable('2Feb', lowBound = 1750, upBound = 3500)
x3 = pulp.LpVariable('3Mar', lowBound = 2000, upBound = 4000)
x4 = pulp.LpVariable('4Apr', lowBound = 2250, upBound = 4500)
x5 = pulp.LpVariable('5May', lowBound = 2000, upBound = 4000)
x6 = pulp.LpVariable('6Jun', lowBound = 1750, upBound = 3500) 

# Subject To 
I1 = 2750
prob += I1

I2 = I1 + x1 - 1000
prob += I2 <= 6000
prob += I2 >= 1500

I3 = I2 + x2 - 4500
prob += I3 <= 6000
prob += I3 >= 1500

I4 = I3 + x3 - 6000
prob += I4 <= 6000
prob += I4 >= 1500

I5 = I4 + x4 - 5500
prob += I5 <= 6000
prob += I5 >= 1500 

I6 = I5 + x5 - 3500
prob += I6 <= 6000 
prob += I6 >= 1500

I7 = I6 + x6 - 4000
prob += I7 <= 6000 
prob += I7 >= 1500

# The Objective Function
z = 240*x1 + 250*x2 + 265*x3 + 285*x4 + 280*x5 + 260*x6 + 3.6*(I1 + I2)/2 + 3.75*(I2 + I3)/2 + 3.98*(I3 + I4)/2 + 4.28*(I4 + I5)/2 + 4.20*(I5 + I6)/2 + 3.9*(I6 + I7)/2

prob += z,'Min_Cost'

# Solve the LP using the GLPK solver. 
result = prob.solve(GLPK(options = ['--ranges', 'sensitivity.txt']))

CBC求解器运行结果

Optimal number of units to build in 1Jan is 4000.0
Optimal number of units to build in 2Feb is 3500.0
Optimal number of units to build in 3Mar is 4000.0
Optimal number of units to build in 4Apr is 4250.0
Optimal number of units to build in 5May is 4000.0
Optimal number of units to build in 6Jun is 3500.0
The end of period inventory is 5750.0
The end of period inventory is 4750.0
The end of period inventory is 2750.0
The end of period inventory is 1500.0
The end of period inventory is 2000.0
The end of period inventory is 1500.0
Total cost is = $ 6,209,432.50

GLPK在Spyder/PuLP中可正常运行其他类似问题,我已通过conda-forge更新,但GLPK版本仍显示为4.65,现寻求该错误的解决方法。

内容的提问来源于stack exchange,提问作者Triss Ashton

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 09:35:00