% Boyd & Vandenberghe "Convex Optimization"
% Joëlle Skaf - 08/16/05
%
% The goal is to find the largest Euclidean ball (i.e. its center and
% radius) that lies in a polyhedron described by linear inequalites in this
% fashion: P = {x : a_i'*x <= b_i, i=1,...,m}

% Generate the data
randn('state',0);
n = 10; m = 2*n;
A = randn(m,n);
b = A*rand(n,1) + 2*rand(m,1);
norm_ai = sum(A.^2,2).^(.5);

% Build and execute model
fprintf(1,'Computing Chebyshev center...');
cvx_begin
    variable r(1)
    variable x_c(n)
    dual variable y
    maximize ( r )
    y: A*x_c + r*norm_ai <= b;
cvx_end
fprintf(1,'Done! \n');

% Display results
fprintf(1,'The Chebyshev center coordinates are: \n');
disp(x_c);
fprintf(1,'The radius of the largest Euclidean ball is: \n');
disp(r);
Computing Chebyshev center... 
Calling Mosek 9.1.9: 20 variables, 11 equality constraints
   For improved efficiency, Mosek is solving the dual problem.
------------------------------------------------------------

MOSEK Version 9.1.9 (Build date: 2019-11-21 11:32:15)
Copyright (c) MOSEK ApS, Denmark. WWW: mosek.com
Platform: MACOSX/64-X86

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

Optimizer started.
Presolve started.
Linear dependency checker started.
Linear dependency checker terminated.
Eliminator started.
Freed constraints in eliminator : 0
Eliminator terminated.
Eliminator - tries                  : 1                 time                   : 0.00            
Lin. dep.  - tries                  : 1                 time                   : 0.00            
Lin. dep.  - number                 : 0               
Presolve terminated. Time: 0.00    
Problem
  Name                   :                 
  Objective sense        : min             
  Type                   : LO (linear optimization problem)
  Constraints            : 11              
  Cones                  : 0               
  Scalar variables       : 20              
  Matrix variables       : 0               
  Integer variables      : 0               

Optimizer  - threads                : 8               
Optimizer  - solved problem         : the primal      
Optimizer  - Constraints            : 11
Optimizer  - Cones                  : 0
Optimizer  - Scalar variables       : 20                conic                  : 0               
Optimizer  - Semi-definite variables: 0                 scalarized             : 0               
Factor     - setup time             : 0.00              dense det. time        : 0.00            
Factor     - ML order time          : 0.00              GP order time          : 0.00            
Factor     - nonzeros before factor : 66                after factor           : 66              
Factor     - dense dim.             : 0                 flops                  : 3.15e+03        
ITE PFEAS    DFEAS    GFEAS    PRSTATUS   POBJ              DOBJ              MU       TIME  
0   3.1e+01  4.7e+00  4.2e+01  0.00e+00   1.800847484e+01   0.000000000e+00   4.8e+00  0.00  
1   1.1e+00  1.7e-01  1.5e+00  -2.05e-01  8.329859321e-01   -1.351392910e-01  1.7e-01  0.01  
2   2.3e-01  3.4e-02  3.1e-01  8.87e-01   4.003042853e-01   2.086959117e-01   3.5e-02  0.01  
3   7.0e-02  1.1e-02  9.4e-02  7.24e-01   3.291684363e-01   2.681986266e-01   1.1e-02  0.01  
4   1.4e-02  8.3e-04  1.2e-02  7.64e-01   3.127686118e-01   3.004715227e-01   1.9e-03  0.01  
5   5.5e-03  3.3e-04  4.7e-03  -1.84e-01  3.243044563e-01   3.181611000e-01   7.3e-04  0.01  
6   1.3e-03  7.8e-05  1.1e-03  7.76e-01   3.341258689e-01   3.326409576e-01   1.7e-04  0.01  
7   8.5e-05  5.0e-06  7.2e-05  1.02e+00   3.368651344e-01   3.367873239e-01   1.1e-05  0.01  
8   6.1e-07  3.6e-08  5.1e-07  1.00e+00   3.370587443e-01   3.370581838e-01   8.0e-08  0.01  
9   6.1e-11  3.6e-12  5.2e-11  1.00e+00   3.370593981e-01   3.370593981e-01   8.0e-12  0.01  
Basis identification started.
Primal basis identification phase started.
Primal basis identification phase terminated. Time: 0.00
Dual basis identification phase started.
Dual basis identification phase terminated. Time: 0.00
Basis identification terminated. Time: 0.00
Optimizer terminated. Time: 0.02    


Interior-point solution summary
  Problem status  : PRIMAL_AND_DUAL_FEASIBLE
  Solution status : OPTIMAL
  Primal.  obj: 3.3705939813e-01    nrm: 1e+00    Viol.  con: 3e-10    var: 0e+00  
  Dual.    obj: 3.3705939807e-01    nrm: 1e+01    Viol.  con: 0e+00    var: 4e-12  

Basic solution summary
  Problem status  : PRIMAL_AND_DUAL_FEASIBLE
  Solution status : OPTIMAL
  Primal.  obj: 3.3705939820e-01    nrm: 1e+00    Viol.  con: 2e-16    var: 0e+00  
  Dual.    obj: 3.3705939807e-01    nrm: 1e+01    Viol.  con: 0e+00    var: 2e-15  
Optimizer summary
  Optimizer                 -                        time: 0.02    
    Interior-point          - iterations : 9         time: 0.01    
      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    

------------------------------------------------------------
Status: Solved
Optimal value (cvx_optval): +0.337059
 
Done! 
The Chebyshev center coordinates are: 
   -0.1116
   -1.5760
    0.1079
   -2.1751
    3.2264
    3.5820
    4.3394
    3.0680
    0.4449
    0.3164

The radius of the largest Euclidean ball is: 
    0.3371