Forum Discussion
FICO
8 years agoCommunity Manager
Error 101 Incompatible types for operator ('set of integer' * 'mpvar' not defined)
I'm trying to solve a VRP-model and I receive "Error 101 Incompatible types for operator ('set of integer' * 'mpvar' not defined)" when I try to run, and I have no idea how to solve this. The error is located at this line:
Obj := sum(vv in Vessels, rr in Routes) C(vv,rr)*x(vv,rr);
where:
Vessels := 1..2;
Routes := 1..132; and declared as set of integer before this.
finalize(Vessels);
finalize(Routes);
declarations
C: dynamic array(Vessels, Routes) of set of integer;
end-declarations
where C is initialized from a txt-file and then finalized:
forall(vv in Vessels, rr in Routes) finalize(C(vv,rr));
All entries in C are integer and C is on the form: (1 1) [ 0 ]
(1 2) [ 1200 ] etc..
And then the decision variable x:
declarations
x: dynamic array(Vessels, Routes) of mpvar;
end-declarations
forall (vv in Vessels, rr in Routes) do
create(x(vv,rr));
x(vv,rr) is_binary;
end-do
Obj is declared as linctr
5 Replies
- FICOCommunity Manager
Given the way how you are using the entries of the array 'C', namely as coefficients to decision variables, it should probably simply be an array of a numeric type and the data file would correspondingly take this form:
C: [ (1 1) 0 (1 2) 1200 !...
]
The resulting model would look as follows (please note the use of 'exists' in the enumerations of dynamic arrays - I have also added a test for non-zero values of 'C', it would be more efficient not to list these entries in the data file):
declarations
Vessels: range
Routes: set of integer
C: dynamic array(Vessels, Routes) of integer;
x: dynamic array(Vessels, Routes) of mpvar;
Obj: linctr
end-declarations
initializations from DATAFILE
C
end-initializations
finalize(Vessels); finalize(Routes)
forall(vv in Vessels, rr in Routes | exists(C(vv,rr)) and C(vv,rr)<>0 ) do
create(x(vv,rr));
x(vv,rr) is_binary;
end-do
Obj := sum(vv in Vessels, rr in Routes | exists(x(vv,rr))) C(vv,rr)*x(vv,rr);
- FICOCommunity Manager
Thank you! But it didn't work quite yet. I removed the zero entries in the C array and added your suggestions. The model compiles successfully, but the optimal value is found to be 0.
Here is the the entire model:
model VRPMod
uses "mmxprs";
options explterm
options noimplicit
parameters
DataFile = 'VRPData.txt';
end-parameters
declarations
nNodes: integer;
nVessels: integer;
nRoutes: integer;
end-declarations
initializations from DataFile
nNodes; nVessels; nRoutes;
end-initializations
declarations
Nodes: set of integer;
Vessels: range;
Routes: set of integer;
end-declarations
Nodes := 1..nNodes;
Vessels := 1..nVessels;
Routes := 1..nRoutes;
finalize(Nodes); finalize(Vessels); finalize(Routes);
declarations
C: dynamic array(Vessels, Routes) of integer;
A: dynamic array(Vessels, Routes, Nodes) of integer;
end-declarations
initializations from DataFile
C; A;
end-initializations
declarations
x: dynamic array(Vessels, Routes) of mpvar;
end-declarations
forall (vv in Vessels, rr in Routes, nn in Nodes | exists(C(vv,rr)) and C(vv,rr)<>0 and exists(A(vv,rr,nn))) do
create(x(vv,rr));
x(vv,rr) is_binary;
end-do
declarations
Obj: linctr;
C1: array(Nodes) of linctr;
C2: array(Vessels) of linctr;
end-declarations
Obj := sum(vv in Vessels, rr in Routes | exists(x(vv,rr))) (C(vv,rr)*x(vv,rr));
!Constraint 1
forall (nn in Nodes) do
C1(nn):= sum(vv in Vessels, rr in Routes | exists(x(vv,rr))) A(vv,rr,nn)*x(vv,rr) >= 1;
end-do
!Constraint 2
forall (vv in Vessels) do
C2(vv):= sum(rr in Routes) x(vv,rr) >= 1;
end-do
minimize(Obj);
write("Optimal distance is: ", getobjval);
writeln(" nm");
end-model
And the datafile:
nVessels: 2
nNodes: 8
nRoutes: 121
C : [ (1 1) 2676 (1 2) 2798 ....
]
A : [ (1 1 1) 1 (1 2 1) 1 ....
]
- FICOCommunity Manager
It may be helpful to add some display of the solver log to see what is happening and also better check the solution status before trying to report anything:
setparam("XPRS_verbose", true); ! Enable solver log display
minimize(Obj);
write("Problem status: ");
case getprobstat of
XPRS_OPT: do
writeln('optimal');
write("Optimal distance is: ", getobjval);
writeln(" nm");
end-do
XPRS_INF: writeln('infeasible');
XPRS_UNB: writeln('unbounded');
XPRS_UNF: writeln('unfinished');
else
writeln('unexpected problem status!');
end-case
Besides that, I would suggest to formulate the tests in the variable creation loop as follows:
forall(vv in Vessels, rr in Routes | exists(C(vv,rr)) and C(vv,rr)<>0 and
(or(nn in Nodes | exists(A(vv,rr,nn))) true) ) do
...
- FICOCommunity Manager
Thank you again. The optimal distance is still 0, and the solver log says the problem is infeasible due to C1(7):
Reading Problem \xprs_9b5a020
Problem Statistics
9 ( 0 spare) rows
80 ( 0 spare) structural columns
160 ( 0 spare) non-zero elements
Global Statistics
80 entities 0 sets 0 set members
Minimizing MILP \xprs_9b5a020
Original problem has:
9 rows 80 cols 160 elements 80 globals
The problem is infeasible due to row C1(7)
*** Search completed *** Time: 0 Nodes: 0
Problem is integer infeasible
Number of integer feasible solutions found is 0
Best bound is -1.00000E+40
Problem status: infeasible
I have no idea why it's infeasible when nn = 7. The A array has the following structure, and the entries when nn = 7 surely exist:
A : [ (1 1 1) 1 (1 1 2) 0 (1 1 3) 0 (1 1 4) 0 (1 1 5) 0 (1 1 6) 0 (1 1 7) 0 (1 2 1) 1 ... ! and repeating
]
Do you have any idea how to solve this?
- FICOCommunity Manager
The infeasibility is detected by presolve, adding the following line before the call to optimization should result in some more detailed output:
setparam("XPRS_TRACE", 1)
(see FICO Xpress Optimization Examples Repository: Folio - Advanced modelling and solving tasks (https://examples.xpress.fico.com/example.pl?id=folioadv_8) for an example of its use).
A more detailed discussion of methods for handling infeasibility can be found here: Handling infeasibility (http://www.fico.com/fico-xpress-optimization/docs/latest/evalguide2/dhtml/eg2sec4.html)
Besides that, given that your problem is not so large, printing out the matrix via 'exportprob' (Mosel problem) or 'writeprob' (to be called after loading it into the solver; Optimizer problem) might be useful too.
Related Content
Related Content
Error 101: Incompatible types for operators
I'm trying to optimize a Power System economic dispatch. My code is the following: model ProblemaMultimodal uses "mmxprs"; !Declaraciones de varaibles y parámetros declarations Pg1:mpvar Pg2...3 years agoPlace FICO® Xpress Optimization ForumFICO® Xpress Optimization Forum1 unread comment1 unread0Views0likes1CommentMosel: E-101: Incompatible types for operator (`mpvar' *SQUARE* `integer' not defined).
Please note syntax is weird in this post because this forum prohibits special characters. I've thus replaced the arrow/hat/square operator with *SQUARE* throughout my post... Hi Again! I am hoping I...6 years agoPlace FICO® Xpress Optimization ForumFICO® Xpress Optimization Forum3 unread comments3 unread0Views0likes3Comments
