Originally posted by: ssly
This has nothing to do with whether a row vector or column vector.
I have encountered the same problem too. Even the vector length is totally consistent, Cplex will still report the error "CPLEX encountered arrays with inconsistent lengths."
As long as modifications are applied to an old model, solving the modified model will cause this error.
What's more are that if you create a new cplex object and replicate all the parameters, this issue will disapper and the model become solvable again. There are something wrong with the underlying model at cplex.Model.
After experiments, I generate the following simple example to demonstrate this issue.
%% We build the simple original problem : min f=x1+x2+x3+x4+x5 subject to:-1<=x1,x2,x3,x4,x5<=1 and -2<=x1+x2+x3+x4+x5<=4
cplex_master=Cplex('Lsh_master');
cplex_master.Model.sense='minimize';
cplex_master.Model.obj=ones(5,1);
cplex_master.Model.lb=-ones(5,1);
cplex_master.Model.ub=ones(5,1);
cplex_master.Model.A = ones(1,5);
cplex_master.Model.lhs = -2;
cplex_master.Model.rhs = 4;
cplex_master.DisplayFunc = [];
try
cplex_master.solve();
catch m
disp (m.message);
end
fprintf('\nSolution status = %s\n',cplex_master.Solution.statusstring);
% the original problem can be solved successfully
%% We now add one extra decision variable x6 to the original problem
cplex_master.Model.obj=ones(6,1);
cplex_master.Model.lb=-ones(6,1);
cplex_master.Model.ub=ones(6,1);
cplex_master.Model.A = ones(1,6);
try
cplex_master.solve();
catch m
disp (m.message);
end
% Now we can not solve this problem, it shows the error "CPLEX encountered arrays with inconsistent lengths." However, the vectors and matrix size are totally correct and consistent with each other.
%% However, if we create a new cplex model and replicate the same new problem, it gets solvable again.
cplex_sub=Cplex('Lsh_sub');
cplex_sub.Model.obj=cplex_master.Model.obj;
cplex_sub.Model.lb=cplex_master.Model.lb;
cplex_sub.Model.ub=cplex_master.Model.ub;
cplex_sub.Model.A = cplex_master.Model.A;
cplex_sub.Model.lhs=cplex_master.Model.lhs;
cplex_sub.Model.rhs = cplex_master.Model.rhs;
try
cplex_sub.solve();
catch m
disp (m.message);
end
#CPLEXOptimizers#DecisionOptimization