Forum Discussion
FICO
6 years agoCommunity Manager
Incompatible data types for operator (Xpress Mosel)
I am currently trying to define a simple model where the goal is to figure out which combination of price, quantity and cost per sale is the profitable as well as calculate the profits for each case as calculated through the objective function.
model "TESTmodel"
uses "mmsheet", "mmxprs"
parameters
MINPROFIT = 1800
declarations
PRODUCTNO = 1..4500
SALESNO = 1..4500
COSTNO = 1..4500
PRICE: array(PRODUCTNO) of integer
QUANTITY: array(SALESNO) of integer
COSTPERSALE: array(COSTNO) of integer
end-declarations
initializations from "SALESDATA.dat"
PRICE QUANTITY COSTPERSALE
end-initializations
Profit:= PRICE * QUANTITY - COSTPERSALE
PRICE * QUANTITY - COSTPERSALE >= MINPROFIT
maximize(Profit)
writeln("Solution:\n Objective: ", getobjval)
forall(p in PRODUCTNO) writeln(" Total Profit is:", getsol(Profit)
end-modelRunning the model however returns the following errors instead:
Mosel: E-101 at (22,27) of `testmosel.mos': Incompatible types for operator (`array of integer' * `array of integer' not defined).
Mosel: E-123 at (22,27) of `testmosel.mos': `Profit' is not defined.
Mosel: E-112 at (22,39) of `testmosel.mos': Numeric expression expected for operator `-'.
Mosel: E-101 at (24,18) of `testmosel.mos': Incompatible types for operator (`array of integer' * `array of integer' not defined).
Mosel: E-112 at (24,33) of `testmosel.mos': Numeric expression expected for operator `-'.
Mosel: E-124 at (24,43) of `testmosel.mos': An expression cannot be used as a statement.
Mosel: E-123 at (26,15) of `testmosel.mos': `Profit' is not defined.
Mosel: E-123 at (28,63) of `testmosel.mos': `Profit' is not defined
Failed to parse Mosel source fileDespite my best efforts to debug the code I have failed to eliminate the error messages. I'm very new to the usage of Xpress Mosel so I would appreciate any form of feedback.
1 Reply
- FICOCommunity Manager
There are several points going wrong here:
- the first error is explained by the fact that you are using arrays without indices in the arithmetic formulae, the correct form needs to be something like:
Profit:= sum(p in PRODUCTNO) (PRICE(p) * QUANTITY(p) - COSTPERSALE(p))
- your program does not contain any optimization objects: what are the decisions to be taken? I assume these may be the entries of the 'QUANTITY' array, in which case this array needs to be declared as 'mpvar' in place of numerical values and you then don't provide any input values for it
- a couple of closing markers such as 'end-parameters' in the beginning or a closing ')' in line 27 are missing
The following model compiles correctly, but I am not certain whether this actually corresponds to the optimization problem that you wish to state:
model "TESTmodel" uses "mmxprs" parameters MINPROFIT = 1800 end-parameters declarations PRODUCTNO = 1..4500 PRICE: array(PRODUCTNO) of integer quantity: array(PRODUCTNO) of mpvar COSTPERSALE: array(PRODUCTNO) of integer end-declarations initializations from "SALESDATA.dat" PRICE COSTPERSALE end-initializations Profit:= sum(p in PRODUCTNO) (PRICE(p) * quantity(p) - COSTPERSALE(p)) sum(p in PRODUCTNO) (PRICE(p) * quantity(p) - COSTPERSALE(p)) >= MINPROFIT maximize(Profit) writeln("Solution:\n Objective: ", getobjval) ! Same as: getsol(Profit) forall(p in PRODUCTNO) writeln(p, ": ", quantity(p).sol) end-model


