I'm starting to use Xpress Fico workbench. I was trying to define a simple model in a model
file in this way:
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
When I try to build the file I receive the following error
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'.
Any suggestion to solve this?
There are two issues in your code,
First you are using c as an iterator in your sum, but it's declared as an array above. So Mosel is complaining by saying that you are using an array in range, which you cannot do. You should not be using an already declared variable as an iterator in Mosel. So I changed your iterator to cc.
Second, you are aiming to take a sum over A(r, c) * x(c). You need parenthesis around them so Mosel knows where your sum ends. Otherwise, it will assume you are only taking sum over the first element A(r, cc).
So your loop should be like this:
forall(r in contraints) do
sum(cc in indexes) (A(r, cc) * x(cc)) <= B(r)! body...
end-do