首页 > 解决方案 > 运算符类型与 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'.

有什么建议可以解决这个问题吗?

标签: optimizationlinear-programmingmosel

解决方案


对上一个答案的更正:Mosel 对运算符的评估应用标准优先规则(即乘法优先于加法),因此从语言的角度来看,乘积术语周围的括号不是必需的 - 尽管它们可能有助于提高可读性- 所以你也可以写:

forall(r in contraints) do
  sum(cc in indexes) A(r, cc) * x(cc) <= B(r)! body...
end-do

推荐阅读