optimization - 运算符类型与 Mosel 不兼容
问题描述
我开始使用 Xpress Fico 工作台。model
我试图以这种方式在文件中定义一个简单的模型:
model ModelName
options noimplicit
uses "mmxprs"
! uses "mminsight" ! uncomment this line for an Xpress Insight model
declarations
! indici
indexes = 1..4
contraints = 1..2
x: array(indexes) of mpvar
c: array(indexes) of integer
A: array(contraints, indexes) of real
B: array(contraints) of real
! Objective:linctr
profit: linctr
end-declarations
!profit:=250*x1+230*x2+110*x3+350*x4
c::[250, 230, 110, 350]
profit:=sum(i in indexes) c(i)*x(i)
! 2*x1+1.5*x2+0.5*x3+2.5*x4<=100
! 0.5*x1+0.25*x2+0.25*x3+x4<=50
A::[ 2, 1.5, 0.5, 2.5,
0.5, 0.25, 0.25, 1]
B::[ 100,
50]
forall(r in contraints) do
sum(c in indexes) A(r, c) * x(c) <= B(r)! body...
end-do
writeln("Begin running model")
maximise(profit)
writeln("profit: ", getobjval)
forall(i in indexes) do
writeln("x( ", i, ")", getsol(x(i)))
end-do
writeln("End running model")
end-model
当我尝试构建文件时,我收到以下错误
Mosel: E-101 at (33,21) of `studio/esL01_01.1.mos': Incompatible types for operator (`array of integer' in `range' not defined).
Mosel: E-151 at (33,31) of `studio/esL01_01.1.mos': Incompatible type for subscript 2 of `A'.
有什么建议可以解决这个问题吗?
解决方案
对上一个答案的更正:Mosel 对运算符的评估应用标准优先规则(即乘法优先于加法),因此从语言的角度来看,乘积术语周围的括号不是必需的 - 尽管它们可能有助于提高可读性- 所以你也可以写:
forall(r in contraints) do
sum(cc in indexes) A(r, cc) * x(cc) <= B(r)! body...
end-do
推荐阅读
- android - 番石榴依赖错误
- python - 过滤多级分组结果
- angular - HttpTestingController expectOne 匹配 URL 错误
- python - WTForms/flaskforms 无法通过提交按钮正确检索数据
- ios - 在 UICollectionView 中向 AVPlayerViewController 添加图像
- r - 从拟合的 lm 或 glm [R] 获取每个因子水平(以及交互作用)中的数据数量
- dynamics-crm - 当 MS 动态返回 HTTP/1.1 500 内部服务器错误时如何检索 http 响应正文?
- bazel - Bazel 的 cc_library 包含路径如何扩展?
- sql-server - Django中的每个用户数据库身份验证
- javascript - 文本区域线检测