4.8 混合整数线性规划

MicroCity使用lpsolveopen in new window来解决混合整数线性规划问题。开发人员可以使用嵌入的Lua函数来构建和求解模型。本章的示例代码可以在项目选项卡中的"optimization_samples"文件夹中找到,图标为图标ScriptEditor.

模型创建和执行

CreateLP ([rows = 0 , columns = 0])

创建一个混合整数线性规划模型并返回LPModel对象。

SetObjFunction (LPModel, rowTable, "MAX"|"MIN")

使用存储决策变量系数的Lua Table设置LPModel的目标函数。

AddConstraint (LPModel, rowTable, "<="|">="|"==", rhsValue)

使用存储决策变量系数的Lua TableLPModel添加约束。

SetInteger (LPModel, index)

将由索引index指定的决策变量设置为整数变量。

SetBinary (LPModel, index)

将由索引index指定的LPModel的决策变量设置为二进制变量。

SetUnbounded (LPModel, index)

将由索引index指定的LPModel的决策变量设置为无界(正/负无穷大)。

SolveLP (LPModel [, timeoutSec = 60])

求解LPModel并返回0表示成功,-1表示无效LP模型,-2表示内存不足,1表示次优,2表示不可行,3表示无界,4表示退化,5表示遇到数值错误,6表示用户中止,7表示超时错误,9表示模型可由预处理解决,10表示B&B例程失败,11表示B&B因中断而停止,12表示找到可行的B&B解决方案,13表示没有可行的B&B解决方案。

GetObjective (LPModel)

返回LPModel的目标函数值。

GetVariable (LPModel, index)

返回由索引index指定的决策变量的值。

GetVariables (LPModel)

返回LPModel的所有决策变量的值。

GetDual (LPModel, index)

返回由索引index指定的决策变量的对偶值。

GetDuals (LPModel)

返回LPModel的所有决策变量的对偶值。

ReadLP("fileName.mps")

从文件(*.lp, *.mps)中读取LPModel,并在成功时返回LPModel

WriteLP (LPModel, "fileName.mps")

LPModel写入文件(*.lp, *.mps),并在成功时返回true。

这篇文章使用ChatGPT翻译自其他语言,如果有问题请在反馈open in new window页面提交反馈。

Last Updated:
Contributors: huuhghhgyg