yalmip / YALMIP

MATLAB toolbox for optimization modeling
https://yalmip.github.io/
Other
492 stars 139 forks source link

gurobi sets incorrect values after solving nonconvex problem #790

Closed pbpf closed 4 years ago

pbpf commented 4 years ago

[yalmip last via git clone]

I try to solve a binear model with solver GUROBI using yalmip.

1st time I got: Successfully solved (GUROBI-NONCONVEX);

but when re-run .m file, there is a error:

> The number of array elements exceeded by the index (3).
> error yalmip (line 827)
            internal_sdpvarstate.optSolution{solutionIndex}.optvar    =
            [oldSolution.optvar(keep_these);newSolution.optvar(:)];

error  solvesdp (line 467)
        yalmip('setsolution',solution_internal);
error  optimize (line 31)
[varargout{1:nargout}] = solvesdp(varargin{:});

I fould clear all can solve this, so it may be cause by gobal variables.

Should we remove all gobal variables in yalmip to avoid this kinds of problems forever?

johanlofberg commented 4 years ago

You would have to supply reproducible example. (You restart YALMIP or clear globals after installing new versions but you never have to clear except for performance reasons in normal use)

pbpf commented 4 years ago

Here is the code ,filename bilinear.m

function bilinear()
% This example formulates and solves the following simple bilinear model:
%  maximize    x
%  subject to  x + y + z <= 10
%              x * y <= 2         (bilinear inequality)
%              x * z + y * z = 1  (bilinear equality)
%              x, y, z non-negative (x integral in second version)

% Copyright 2020, Gurobi Optimization, LLC

% Linear constraint matrix
x=sdpvar(1,1);
y=sdpvar(1,1);
z=sdpvar(1,1);
obj=-x;
con=[x+y+z<=10;x*y>=2;x*z+y*z==1;x>=0;y>=0];
ops = sdpsettings('verbose',0,'solver','GUROBI');%,'GUROBI.IterationLimit',20);%%mosek GUROBI
%      ops = sdpsettings('verbose',1,'solver','ecos','ecos.maxit',10);%,'GUROBI.OptimalityTol',1e-8,'GUROBI.FeasibilityTol',2e-5);
result=optimize(con,obj,ops);
disp(result.info);
disp(value(x));
end

You would have to supply reproducible example. (You restart YALMIP or clear globals after installing new versions but you never have to clear except for performance reasons in normal use)