用 GMPL 建模还是相当方便直观的,但CPLEX/Gurobi貌似不能直接读 GMPL 模型,好在 GLPK 提供把 GMPL 转成 MPS 或 LP 格式的功能:
MPS:
glpsol --math XXXX.gmpl --wmps YYY.mps --check
LP:
glpsol --math XXXX.gmpl --wlp YYY.mps --check
其中 --check 表示只检查,不启动求解过程。
在 Gurobi 中:
m=read("YYY.mps");
m.optimize()
在 CPLEX 中
read YYY.mps mps
optimize
write ZZZ.xml sol
最后一行表示把结果输出到文件 ZZZ.xml 中。