Zero values for Mixed integer optimization

176 views
Skip to first unread message

Bilal Najjar

unread,
Dec 14, 2017, 3:52:11 AM12/14/17
to YALMIP
Hello everybody, 
I am trying to a mixed integer optimization problem using yalmip with mosek solver, you can see the script in the attachment . I was wondering what does this result mean? Any help would be appreciated. 

>> yalmip_optimization

options = 

                   solver: 'mosek'
                  verbose: 1
                    debug: 0
                    usex0: 0
                  warning: 1
             cachesolvers: 0
             showprogress: 0
                saveduals: 1
         removeequalities: 0
         savesolveroutput: 0
          savesolverinput: 0
          saveyalmipmodel: 0
        convertconvexquad: 1
    assertgpnonnegativity: 1
             thisisnotagp: 0
                   radius: Inf
                    relax: 0
                  dualize: 0
                savedebug: 0
                   expand: 1
                allowmilp: 1
           allownonconvex: 1
                    shift: 0
                   dimacs: 0
            beeponproblem: [-5 -4 -3 -2 -1]
                bisection: [1x1 struct]
                  bilevel: [1x1 struct]
                   bmibnb: [1x1 struct]
                      bnb: [1x1 struct]
                   cutsdp: [1x1 struct]
                      kkt: [1x1 struct]
                   moment: [1x1 struct]
                       mp: [1x1 struct]
                    mpcvx: [1x1 struct]
                     plot: [1x1 struct]
                   robust: [1x1 struct]
                      sos: [1x1 struct]
                  refiner: [1x1 struct]
                    baron: []
                 bintprog: [1x1 struct]
                   bonmin: []
                     cdcs: [1x1 struct]
                      cdd: [1x1 struct]
                      cbc: [1x1 struct]
                      clp: [1x1 struct]
                    cplex: [1x1 struct]
                     csdp: [1x1 struct]
                     dsdp: [1x1 struct]
                     ecos: []
                 filtersd: [1x1 struct]
                  fmincon: [1x1 struct]
               fminsearch: [1x1 struct]
                    frlib: [1x1 struct]
                     glpk: [1x1 struct]
                   gurobi: [1x1 struct]
                    ipopt: [1x1 struct]
               intlinprog: [1x1 optim.options.Intlinprog]
                   knitro: [1x1 struct]
                  linprog: [1x1 struct]
                   lmilab: [1x1 struct]
                  lmirank: [1x1 struct]
                logdetppa: [1x1 struct]
                  lpsolve: [1x1 struct]
                lsqnonneg: [1x1 struct]
                   lsqlin: [1x1 struct]
                     kypd: [1x1 struct]
                      nag: [1x1 struct]
                    mosek: [1x1 struct]
                    nomad: []
                     ooqp: []
                   penbmi: [1x1 struct]
                   penlab: []
                   pensdp: [1x1 struct]
                      pop: [1x1 struct]
                  qpoases: []
                     osqp: []
                    qsopt: [1x1 struct]
                 quadprog: [1x1 struct]
               quadprogbb: [1x1 struct]
                     scip: []
                      scs: [1x1 struct]
                     sdpa: [1x1 struct]
                    sdplr: [1x1 struct]
                    sdpt3: [1x1 struct]
                   sdpnal: [1x1 struct]
                   sedumi: [1x1 struct]
                sparsepop: [1x1 struct]
               sparsecolo: [1x1 struct]
                     vsdp: [1x1 struct]
                   xpress: []

Optimizer summary
  Optimizer                 -                        time: 0.00    
    Interior-point          - iterations : 0         time: 0.00    
      Basis identification  -                        time: 0.00    
        Primal              - iterations : 0         time: 0.00    
        Dual                - iterations : 0         time: 0.00    
        Clean primal        - iterations : 0         time: 0.00    
        Clean dual          - iterations : 0         time: 0.00    
    Simplex                 -                        time: 0.00    
      Primal simplex        - iterations : 0         time: 0.00    
      Dual simplex          - iterations : 0         time: 0.00    
    Mixed integer           - relaxations: 0         time: 0.00    


mosek111.png

Johan Löfberg

unread,
Dec 14, 2017, 3:56:17 AM12/14/17
to YALMIP
mosek reports the work done and you see the problem was absolutely trivial. it took zero seconds to solve, it did 0 iterations, zero relaxations, zero ...

Bilal Najjar

unread,
Dec 14, 2017, 4:20:57 AM12/14/17
to YALMIP
Thank you for your reply. What is the minimum value of T "my objective function''  and what are the values of the corresponding variables values? 
minumt.png

Johan Löfberg

unread,
Dec 14, 2017, 4:44:22 AM12/14/17
to YALMIP

Bilal Najjar

unread,
Dec 14, 2017, 5:19:24 AM12/14/17
to YALMIP
this is my code 
deltab = num(1:264,:);
bbefre = num(269:2:end,3);
position = intvar(288,1);
Bcentric = sdpvar(264,1);
      T  = sdpvar(1);
      
Constraints = [deltab * position - Bcentric  + bbefre <=  0.5.*T, ... 
    deltab * position - Bcentric  + bbefre >= - 0.5.*T, 0 <= position <= 3, T > 0];
Objective = min(T);
% Set some options for YALMIP and solver
options =  sdpsettings('solver','mosek','debug',1)
% Solve the problem
sol = optimize(Constraints,Objective,options);

if sol.problem == 0
 % Extract and display value
 solution = value(T)
else
 display('Hmm, something went wrong!');
 yalmiperror(sol.problem)
end
.................................................................................................
and this this the message I got 

Reference to non-existent field 'sol'.

Error in callmosek>call_mosek_lpqp (line 503)
    sol = res.sol;

Error in callmosek>call_mosek_lpqpsocpsdp (line 89)
    [x,D_struc,problem,r,res,solvertime,prob] = call_mosek_lpqp(model);

Error in callmosek (line 51)
    [x,D_struc,problem,r,res,solvertime,prob] = call_mosek_lpqpsocpsdp(model);

Error in solvesdp (line 350)
    eval(['output = ' solver.call '(interfacedata);']);

Error in optimize (line 31)
[varargout{1:nargout}] = solvesdp(varargin{:});

Error in yalmip_optimization (line 17)
sol = optimize(Constraints,Objective,options);

Johan Löfberg

unread,
Dec 14, 2017, 5:22:59 AM12/14/17
to YALMIP
Undefined function or variable 'num'.
 

Johan Löfberg

unread,
Dec 14, 2017, 5:26:42 AM12/14/17
to YALMIP
and minimizing min(T) is an unneccesarily complicated statement. As T is a scalar, min(T) is T, so your objective is simply T. If T would have been a vector, minimizing min(T) would have lead to a nonconvex objective

Bilal Najjar

unread,
Dec 14, 2017, 5:37:36 AM12/14/17
to YALMIP
I changed my objective function as you said but still have the same error 
Reference to non-existent field 'sol'.

Error in callmosek>call_mosek_lpqp (line 503)
    sol = res.sol;

Error in callmosek>call_mosek_lpqpsocpsdp (line 89)
    [x,D_struc,problem,r,res,solvertime,prob] = call_mosek_lpqp(model);

Error in callmosek (line 51)
    [x,D_struc,problem,r,res,solvertime,prob] = call_mosek_lpqpsocpsdp(model);

Error in solvesdp (line 350)
    eval(['output = ' solver.call '(interfacedata);']);

Error in optimize (line 31)
[varargout{1:nargout}] = solvesdp(varargin{:});

Error in yalmip_optimization (line 17)
sol = optimize(Constraints,Objective,options);
............................................................
.If you want to take a look you can find  the whole code and my data in the attachment ! 
before_second_try.xlsx
yalmip_optimization.m

Johan Löfberg

unread,
Dec 14, 2017, 5:47:16 AM12/14/17
to YALMIP
The comment on the objective was a general comment, not related to your problems. Also note that you have a strict inequality on T, which isn't supported really, as it doesn't make sense mathematically in practice.

However, the code runs here. Mosek trivially solves the problem, and returns a solution to YALMIP

Hence, does mosek really work on your machine (have you for example tested yalmiptest('mosek'), or solved a trivial problem such as sdpvar x; optimize(x>=0,x,sdpsettings('solver','mosek'))


Problem
  Name                   :                 
  Objective sense        : min             
  Type                   : LO (linear optimization problem)
  Constraints            : 1105            
  Cones                  : 0               
  Scalar variables       : 553             
  Matrix variables       : 0               
  Integer variables      : 288             

Optimizer started.
Mixed integer optimizer started.
Threads used: 2
Presolve started.
Presolve terminated. Time = 0.06
Presolved problem: 553 variables, 528 constraints, 153120 non-zeros
Presolved problem: 288 general integer, 0 binary, 265 continuous
Clique table size: 0
BRANCHES RELAXS   ACT_NDS  DEPTH    BEST_INT_OBJ         BEST_RELAX_OBJ       REL_GAP(%)  TIME  
0        1        0        0        NA                   0.0000000000e+00     NA          0.2   
0        1        0        0        0.0000000000e+00     0.0000000000e+00     0.00e+00    0.2   
An optimal solution satisfying the relative gap tolerance of 1.00e-02(%) has been located.
The relative gap is 0.00e+00(%).
An optimal solution satisfying the absolute gap tolerance of 0.00e+00 has been located.
The absolute gap is 0.00e+00.

Objective of best integer solution : 0.000000000000e+00      
Best objective bound               : 0.000000000000e+00      
Construct solution objective       : Not employed
Construct solution # roundings     : 0
User objective cut value           : 0
Number of cuts generated           : 0
Number of branches                 : 0
Number of relaxations solved       : 1
Number of interior point iterations: 0
Number of simplex iterations       : 0
Time spend presolving the root     : 0.06
Time spend in the heuristic        : 0.00
Time spend in the sub optimizers   : 0.00
  Time spend optimizing the root   : 0.03
Mixed integer optimizer terminated. Time: 0.20

Optimizer terminated. Time: 0.31    


Integer solution solution summary
  Problem status  : PRIMAL_FEASIBLE
  Solution status : INTEGER_OPTIMAL
  Primal.  obj: 0.0000000000e+00    nrm: 3e-01    Viol.  con: 0e+00    var: 0e+00    itg: 0e+00  
Optimizer summary
  Optimizer                 -                        time: 0.31    
    Interior-point          - iterations : 0         time: 0.00    
      Basis identification  -                        time: 0.00    
        Primal              - iterations : 0         time: 0.00    
        Dual                - iterations : 0         time: 0.00    
        Clean primal        - iterations : 0         time: 0.00    
        Clean dual          - iterations : 0         time: 0.00    
    Simplex                 -                        time: 0.00    
      Primal simplex        - iterations : 0         time: 0.00    
      Dual simplex          - iterations : 0         time: 0.00    
    Mixed integer           - relaxations: 1         time: 0.20    


solution =

     0

Johan Löfberg

unread,
Dec 14, 2017, 5:48:16 AM12/14/17
to YALMIP
and are you using the most recent version of YALMIP and Mosek?

Bilal Najjar

unread,
Dec 14, 2017, 6:42:31 AM12/14/17
to YALMIP
I tried to run this command and I got this message

|                   Test|   Solution|                                                                                        Solver message|
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|   Core functionalities|        N/A|                                                                          Successfully solved (YALMIP)|
|                     LP|        N/A|   Unknown problem in solver (Turn on 'debug' in sdpsettings) (Reference to non-existent field 'sol'.)|
|                     LP|        N/A|   Unknown problem in solver (Turn on 'debug' in sdpsettings) (Reference to non-existent field 'sol'.)|
|                     QP|        N/A|   Unknown problem in solver (Turn on 'debug' in sdpsettings) (Reference to non-existent field 'sol'.)|
|                     QP|        N/A|   Unknown problem in solver (Turn on 'debug' in sdpsettings) (Reference to non-existent field 'sol'.)|
|                   SOCP|        N/A|   Unknown problem in solver (Turn on 'debug' in sdpsettings) (Reference to non-existent field 'sol'.)|
|                   SOCP|        N/A|   Unknown problem in solver (Turn on 'debug' in sdpsettings) (Reference to non-existent field 'sol'.)|
|                   SOCP|        N/A|   Unknown problem in solver (Turn on 'debug' in sdpsettings) (Reference to non-existent field 'sol'.)|
|                    SDP|        N/A|   Unknown problem in solver (Turn on 'debug' in sdpsettings) (Reference to non-existent field 'sol'.)|
|                    SDP|        N/A|   Unknown problem in solver (Turn on 'debug' in sdpsettings) (Reference to non-existent field 'sol'.)|
|                    SDP|        N/A|   Unknown problem in solver (Turn on 'debug' in sdpsettings) (Reference to non-existent field 'sol'.)|
|                    SDP|        N/A|   Unknown problem in solver (Turn on 'debug' in sdpsettings) (Reference to non-existent field 'sol'.)|
|                 MAXDET|        N/A|   Unknown problem in solver (Turn on 'debug' in sdpsettings) (Reference to non-existent field 'sol'.)|
|                 MAXDET|        N/A|   Unknown problem in solver (Turn on 'debug' in sdpsettings) (Reference to non-existent field 'sol'.)|
|          Infeasible LP|        N/A|   Unknown problem in solver (Turn on 'debug' in sdpsettings) (Reference to non-existent field 'sol'.)|
|          Infeasible QP|        N/A|   Unknown problem in solver (Turn on 'debug' in sdpsettings) (Reference to non-existent field 'sol'.)|
|         Infeasible SDP|        N/A|   Unknown problem in solver (Turn on 'debug' in sdpsettings) (Reference to non-existent field 'sol'.)|
|      Moment relaxation|        NAN|                                                                             Unknown problem in YALMIP|
|         Sum-of-squares|        NAN|                                                                             Unknown problem in YALMIP|
|           Bilinear SDP|        N/A|                                                                         Solver not applicable (mosek)|
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
I tried to run the simple problem you mentioned and I got this message

Reference to non-existent field 'sol'.

Error in callmosek>MosekYALMIPError (line 241)
switch res.sol.itr.prosta

Error in callmosek>call_mosek_lpqpsocpsdpdual (line 213)
problem = MosekYALMIPError(res);

Error in callmosek>call_mosek_lpqpsocpsdp (line 81)
    [x,D_struc,problem,r,res,solvertime,prob] = call_mosek_lpqpsocpsdpdual(model);

Error in callmosek (line 51)
    [x,D_struc,problem,r,res,solvertime,prob] = call_mosek_lpqpsocpsdp(model);

Error in solvesdp (line 350)
    eval(['output = ' solver.call '(interfacedata);']);

Error in optimize (line 31)
[varargout{1:nargout}] = solvesdp(varargin{:});

Error in simple_problem (line 1)
 sdpvar x; optimize(x>=0,x,sdpsettings('solver','mosek','debug',1))
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Yesterday I downloaded the latest versions of both yalmip and mosek. 

Johan Löfberg

unread,
Dec 14, 2017, 6:45:44 AM12/14/17
to YALMIP
It thus appears as if mosek does not work on your machine, and you should start by making sure it does (outside YALMIP)

Bilal Najjar

unread,
Dec 14, 2017, 8:50:30 AM12/14/17
to YALMIP
Now it works fine and I got the same result you got. However, the result "0" for the objective function and for the all variables "position" is not convenient and makes no sense!.I tried to solve this problem using cvx and I got the same result  Zero.I asked cvx team for the reason behind this result and they said that cvx works fine and it solves the problem  but there is something wrong in the model itself  or in the inputs. I am pretty sure that there is nothing wrong in the inputs. 
 I am doing the same optimization process mentioned here in this paper and they said that they solved it using YALMIP. 
Can you please tell whether I am doing some mistakes??? 
P.S I changed the objective function to the one mentioned in the paper and I got the same result. 
I hope you can help me and I would be very grateful to you. 



Johan Löfberg

unread,
Dec 14, 2017, 8:58:38 AM12/14/17
to YALMIP
If it does not make any sense, your definition "make sense" should be defined mathematically, and thus constitute a constraint which currently isn't satisfied.

If you optimize a car and minimize it's length and the length turns out to be 0, you are obviously missing something in the model. It does not make sense as people should fit into the car. Have you added the constraint that "people should fit in car". If not, well then you have to add that constraint of course.

Bilal Najjar

unread,
Dec 14, 2017, 11:32:43 AM12/14/17
to YALMIP
 Therefore, in my last reply, I mentioned that this exact optimization problem was solved before using the same YALMIP tool. I have implemented the same exact process step by step and written the same syntax but didn't get the result I was expecting. It seems I'd made some errors when acquiring my data.

Bilal Najjar

unread,
Dec 17, 2017, 3:56:20 PM12/17/17
to YALMIP
Dear Prof Löfberg,
do you please have time to check this paper and see whether I'm doing a mistake? 
I would appreciate that and would be very grateful to you! 
I recorded my data 3 times again and still have the same result for Xi that is zeroes. 

Johan Löfberg

unread,
Dec 18, 2017, 4:18:54 AM12/18/17
to YALMIP
You  are minimizing abs(2*(deltab * position - Bcentric + bbefre)) as your model is equivalent to 

[-0.5*T <= deltab * position - Bcentric + bbefre <=  0.5.*T]

That means

1. It makes absolutely no sense to have the constraint T>0. If the optimal minimal absolute value is 0, why should you artificially enforce T to be > 0. If you want that, solve the problem, and simply add 0.00000000000001 to T. MAkes no sense though

2. You are not implementing the same model as in the paper. You failed with signs when you moved around the terms in the objective. THe model in the paper is 
 [-0.5*T-bbefre <= deltab * position - Bcentric <=  0.5.*T + bbefre]

Correcting the constraints still lead to a solution where optimal T is zero (of course, as this basically is absolute value with a dead-zone, so easier than above to onbtain zero objective)




Bilal Najjar

unread,
Dec 18, 2017, 5:52:35 AM12/18/17
to YALMIP
Thank you so much Sir! I really appreciate that. 
I did correct the constraints as you said. I got some values for Bcentric, T=0 and  Positions are always zeroes. Here is my problem with values of positions. Positions(that is Xi) indicate the number of magnet pieces at location i one has to add to minimize T. The result says you'll get minimum T when you no pieces! nothing!  This is why I am confused. Do I misunderstand something? Sorry but this is my first experience with optimization. 

Johan Löfberg

unread,
Dec 18, 2017, 5:58:39 AM12/18/17
to YALMIP
But do you understand why the objective is what it is? As it is now, the data you have simply says that an objective of 0 can be achieved. You should be able to see that if you understand what you are modelling.

You are doing something like minimize T subject to        [-2 - T <= x-1 <= 2 + T, T>=0]. Clearly, x=0 works and leads to T=0 which is optimal.
Reply all
Reply to author
Forward
0 new messages