%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
%
%     This is an example call of MIDACO 6.0
%     -------------------------------------
%
%     MIDACO solves Multi-Objective Mixed-Integer Non-Linear Problems:
%
%
%      Minimize     F_1(X),... F_O(X)  where X(1,...N-NI)   is CONTINUOUS
%                                      and   X(N-NI+1,...N) is DISCRETE
%
%      subject to   G_j(X)  =  0   (j=1,...ME)      equality constraints
%                   G_j(X) >=  0   (j=ME+1,...M)  inequality constraints
%
%      and bounds   XL <= X <= XU
%
%
%     The problem statement of this example is given below. You can use 
%     this example as template to run your own problem. To do so: Replace 
%     the objective functions 'F' (and in case the constraints 'G') given 
%     here with your own problem and follow the below instruction steps.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
function example
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%   MAIN PROGRAM   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 key = '************************************************************';    
 problem.func = @problem_function; % Call is [f,g] = problem_function(x)        
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Step 1: Problem definition     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  
% STEP 1.A: Problem dimensions
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
problem.o  = 1; % Number of objectives
problem.n  = 26 % Number of variables (in total)
problem.ni = 6; % Number of integer variables (0 <= ni <= n)
problem.m  = 43; % Number of constraints (in total)
problem.me = 0; % Number of equality constraints (0 <= me <= m)
     
% STEP 1.B: Lower and upper bounds 'xl' & 'xu'  
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
problem.xl   = -100 * ones(1,problem.n);
problem.xu   =  100 * ones(1,problem.n);  
% special bounds from GAMS
problem.xl(7) = 2;
problem.xu(7) = 5.4772;  
problem.xl(8) = 3;
problem.xu(8) = 6.7081;   
problem.xl(9) = 3.8;
problem.xu(9) = 7.5498;   
problem.xl(10) = 10;
problem.xu(10) = 10.0001;    
problem.xl(11) = 1.8258;
problem.xu(11) = 5;      
problem.xl(12) = 2.2361;
problem.xu(12) = 5;  
problem.xl(13) = 2.5166;
problem.xu(13) = 5;    
problem.xl(13) = 5;
problem.xu(13) = 5.0001;     
% binaries
problem.xl(21:26)   = 0;
problem.xu(21:26)   = 1; 

% STEP 1.C: Starting point 'x'  
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
problem.x  = problem.xl; % Here for example: 'x' = lower bounds 'xl'
 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Step 2: Choose stopping criteria and printing options    %%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% STEP 2.A: Stopping criteria 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
option.maxeval  = 999999999;    % Maximum number of function evaluation (e.g. 1000000)
option.maxtime  = 60*60*24; % Maximum time limit in Seconds (e.g. 1 Day = 60*60*24)

% STEP 2.B: Printing options  
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
option.printeval  = 10000;  % Print-Frequency for current best solution (e.g. 1000)
option.save2file  = 1;     % Save SCREEN and SOLUTION to TXT-files [ 0=NO/ 1=YES]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Step 3: Choose MIDACO parameters (FOR ADVANCED USERS)    %%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

option.param( 1) =  0;  % ACCURACY  
option.param( 2) =  0;  % SEED      
option.param( 3) =  37.8;  % FSTOP
option.param( 4) =  0;  % ALGOSTOP
option.param( 5) =  0;  % EVALSTOP  
option.param( 6) =  0;  % FOCUS
option.param( 7) =  0;  % ANTS
option.param( 8) =  0;  % KERNEL
option.param( 9) =  0;  % ORACLE    
option.param(10) =  0;  % PARETOMAX   
option.param(11) =  0;  % EPSILON   
option.param(12) =  0;  % BALANCE
option.param(13) =  0;  % CHARACTER  

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Step 4: Choose Parallelization Factor   %%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

option.parallel = 0;  % Serial: 0 or 1, Parallel: 2,3,4,5,6,7,8...  

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%   Call MIDACO solver   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[ solution ] = midaco( problem, option, key);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%   End of Example    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%   OPTIMIZATION PROBLEM   %%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [ f, g ] = problem_function( x )

      y = x(21:26);

      x8 = x(1);
      x9 = x(2);
      x10 = x(3);
      x11 = x(4);
      x12 = x(5);
      x13 = x(6);
      x14 = x(7);
      x15 = x(8);
      x16 = x(9);
      x17 = x(10);
      x18 = x(11);
      x19 = x(12);
      x20 = x(13);
      x21 = x(14);
      x22 = x(15);
      x23 = x(16);
      x24 = x(17);
      x25 = x(18);
      x26 = x(19);
      x27 = x(20);
      b1 = y(1);
      b2 = y(2);
      b3 = y(3);
      b4 = y(4);
      b5 = y(5);
      b6 = y(6);

      f = 6*x10 + 6*x11 + 6*x12 + 6*x13;

      e2 = x22 - x23;     
      e3 = 0.5*x14 - x17 + x22;                          
      e4 = 0.5*x14 - x22; 
      e5 = 0.5*x18 - x21 + x25;                      
      e6 = 0.5*x18 - x25; 
      e7 = 0.5*x15 - x17 + x23;                                  
      e8 = 0.5*x15 - x23; 
      e9 = 0.5*x19 - x21 + x26;                   
      e10 = 0.5*x19 - x26;
      e11 = 0.5*x16 - x17 + x24;                 
      e12 = 0.5*x16 - x24;
      e13 = 0.5*x20 - x21 + x27;             
      e14 = 0.5*x20 - x27;
      e15 = -x8 + x22 - x23;                                      
      e16 = -x8 - x22 + x23;                                      
      e17 = -x9 + x25 - x26;                                      
      e18 = -x9 - x25 + x26;                                      
      e19 = -10*b1 - 10*b2 + 0.5*x14 + 0.5*x15 - x22 + x23;     
      e20 = -10*b1 + 10*b2 + 0.5*x14 + 0.5*x15 + x22 - x23 - 10;
      e21 = 5*b1 - 5*b2 + 0.5*x18 + 0.5*x19 - x25 + x26 - 5;   
      e22 = 5*b1 + 5*b2 + 0.5*x18 + 0.5*x19 + x25 - x26 - 10;  
      e23 = -x10 + x22 - x24;                                     
      e24 = -x10 - x22 + x24;                                     
      e25 = -x11 + x25 - x27;                                     
      e26 = -x11 - x25 + x27;                                     
      e27 = -10*b3 - 10*b4 + 0.5*x14 + 0.5*x16 - x22 + x24; 
      e28 = -10*b3 + 10*b4 + 0.5*x14 + 0.5*x16 + x22 - x24 - 10;
      e29 = 5*b3 - 5*b4 + 0.5*x18 + 0.5*x20 - x25 + x27 - 5;   
      e30 = 5*b3 + 5*b4 + 0.5*x18 + 0.5*x20 + x25 - x27  - 10;  
      e31 = -x12 + x23 - x24;                                     
      e32 = -x12 - x23 + x24;                                     
      e33 = -x13 + x26 - x27;                                     
      e34 = -x13 - x26 + x27;                                     
      e35 = -10*b5 - 10*b6 + 0.5*x15 + 0.5*x16 - x23 + x24; 
      e36 = -10*b5 + 10*b6 + 0.5*x15 + 0.5*x16 + x23 - x24 - 10;
      e37 = 5*b5 - 5*b6 + 0.5*x19 + 0.5*x20 - x26 + x27 - 5;   
      e38 = 5*b5 + 5*b6 + 0.5*x19 + 0.5*x20 + x26 - x27 - 10;  
      e39 = 10/x14 - x18;    
      e40 = 10/x18 - x14;    
      e41 = 15/x15 - x19;    
      e42 = 15/x19 - x15;    
      e43 = 19/x16 - x20;    
      e44 = 19/x20 - x16;    

      
      g(1) = -e2;
      g(2) = -e3;
      g(3) = -e4;
      g(4) = -e5;
      g(5) = -e6;
      g(6) = -e7;
      g(7) = -e8;
      g(8) = -e9;
      g(9) = -e10;
      g(10) = -e11;
      g(11) = -e12;
      g(12) = -e13;
      g(13) = -e14;
      g(14) = -e15;
      g(15) = -e16;
      g(16) = -e17;
      g(17) = -e18;
      g(18) = -e19;
      g(19) = -e20;
      g(20) = -e21;
      g(21) = -e22;
      g(22) = -e23;
      g(23) = -e24;
      g(24) = -e25;
      g(25) = -e26;
      g(26) = -e27;
      g(27) = -e28;
      g(28) = -e29;
      g(29) = -e30;
      g(30) = -e31;
      g(31) = -e32;
      g(32) = -e33;
      g(33) = -e34;
      g(34) = -e35;
      g(35) = -e36;
      g(36) = -e37;
      g(37) = -e38;
      g(38) = -e39;
      g(39) = -e40;
      g(40) = -e41;
      g(41) = -e42;
      g(42) = -e43;
      g(43) = -e44;  
  
end

function [y] = SQR(x)
y = x^2;
return
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%   END OF FILE   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
