%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
%
%     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  = 46; % Number of variables (in total)
problem.ni = 24; % Number of integer variables (0 <= nint <= n)
problem.m  = 73; % Number of constraints (in total)
problem.me = 12; % Number of equality constraints (0 <= me <= m)
     
% STEP 1.B: Lower and upper bounds 'xl' & 'xu'  
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
  xl   =    0 * ones(1,problem.n);
  xu   = 1000 * ones(1,problem.n); 
% Binaries  
  xl(23:46) = 0;
  xu(23:46) = 1;  
% Some special bounds from GAMS Reference
  xu(1) = 1.38629436111989; 
  xu(2) = 1.38629436111989; 
  xu(3) = 1.38629436111989; 
  xu(4) = 1.38629436111989; 
  xu(5) = 1.38629436111989; 
  xu(6) = 1.38629436111989; 
  xl(7) = 5.7037824746562;
  xu(7) = 8.00636756765025; 
  xl(8) = 5.7037824746562;
  xu(8) = 8.00636756765025; 
  xl(9) = 5.7037824746562;
  xu(9) = 8.00636756765025; 
  xl(10) = 5.7037824746562;
  xu(10) = 8.00636756765025; 
  xl(11) = 5.7037824746562;
  xu(11) = 8.00636756765025; 
  xl(12) = 5.7037824746562; 
  xu(12) = 8.00636756765025; 
  xl(13) = 4.45966; 
  xu(13) = 397.747; 
  xl(14) = 3.7495;
  xu(14) = 882.353; 
  xl(15) = 4.49144; 
  xu(15) = 833.333; 
  xl(16) = 3.14988; 
  xu(16) = 638.298; 
  xl(17) = 3.04452; 
  xu(17) = 666.667; 
  xl(18) = 0.729961; 
  xu(18) = 2.11626; 
  xl(19) = 0.530628; 
  xu(19) = 1.91626; 
  xl(20) = 1.09024; 
  xu(20) = 2.47654; 
  xl(21) = -0.133531; 
  xu(21) = 1.25276; 
  xl(22) = 0.0487901; 
  xu(22) = 1.43508;    
% Declare bounds for MIDACO as problem.xl and problem.xu
  problem.xl = xl;
  problem.xu = xu;

% 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  = 100000;  % 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.01;  % ACCURACY  
option.param( 2) =  0;  % SEED      
option.param( 3) =  285506.51;  % 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 )


% Rename integer variables as 'y'
  y = x(23:46);

% Rename variables to fit GAMS format  
  x1 = x(1);
  x2 = x(2);
  x3 = x(3);
  x4 = x(4);
  x5 = x(5);
  x6 = x(6);
  x7 = x(7);
  x8 = x(8);
  x9 = x(9);
  x10 = x(10);
  x11 = x(11);
  x12 = x(12);
  x13 = x(13);
  x14 = x(14);
  x15 = x(15);
  x16 = x(16);
  x17 = x(17);
  x18 = x(18);
  x19 = x(19);
  x20 = x(20);
  x21 = x(21);
  x22 = x(22);
  b23 = y(1);
  b24 = y(2);
  b25 = y(3);
  b26 = y(4);
  b27 = y(5);
  b28 = y(6);
  b29 = y(7);
  b30 = y(8);
  b31 = y(9);
  b32 = y(10);
  b33 = y(11);
  b34 = y(12);
  b35 = y(13);
  b36 = y(14);
  b37 = y(15);
  b38 = y(16);
  b39 = y(17);
  b40 = y(18);
  b41 = y(19);
  b42 = y(20);
  b43 = y(21);
  b44 = y(22);
  b45 = y(23);
  b46 = y(24);

% Objective function value F(X)
  f = 250.0*exp(x1 + 0.6*x7) + 250.0*exp(x2 + 0.6*x8) ...
    + 250.0*exp(x3 + 0.6*x9) + 250.0*exp(x4 + 0.6*x10) ...
    + 250.0*exp(x5 + 0.6*x11) ...
    + 250.0*exp(x6 + 0.6*x12) ;

% Equality constraints G(X) = 0 MUST COME FIRST in g(1:me)  
  e2 = x7 - x13 - 2.06686275947298;
  e3 = x8 - x13 - 0.693147180559945;
  e4 = x9 - x13 - 1.64865862558738;
  e5 = x10 - x13 - 1.58923520511658;
  e6 = x11 - x13 - 1.80828877117927;
  e7 = x12 - x13 - 1.43508452528932;
  e8 = x7 - x14 + 0.356674943938732;
  e9 = x8 - x14 + 0.22314355131421;
  e10 = x9 - x14 + 0.105360515657826;
  e11 = x10 - x14 - 1.22377543162212;
  e12 = x11 - x14 - 0.741937344729377;
  e13 = x12 - x14 - 0.916290731874155;
  
% Inequality constraints G(X) >= 0 MUST COME SECOND in g(me+1:m)  
  e14 = x7 - x15 -0.356674943938732;
  e15 = x8 - x15 - 0.955511445027436;
  e16 = x9 - x15 - 0.470003629245736;
  e17 = x10 - x15 - 1.28093384546206;
  e18 = x11 - x15 - 1.16315080980568;
  e19 = x12 - x15 - 1.06471073699243;
  e20 = x7 - x16 - 1.54756250871601;
  e21 = x8 - x16 - 0.832909122935104;
  e22 = x9 - x16 - 0.470003629245736;
  e23 = x10 - x16 - 0.993251773010283;
  e24 = x11 - x16 - 0.182321556793955;
  e25 = x12 - x16 - 0.916290731874155;
  e26 = x7 - x17 - 0.182321556793955;
  e27 = x8 - x17 - 1.28093384546206;
  e28 = x9 - x17 - 0.8754687373539;
  e29 = x10 - x17 - 1.50407739677627;
  e30 = x11 - x17 - 0.470003629245736;
  e31 = x12 - x17 - 0.741937344729377;
  e32 = x1 + x18 - 1.85629799036563;
  e33 = x2 + x18 - 1.54756250871601;
  e34 = x3 + x18 - 2.11625551480255;
  e35 = x4 + x18 - 1.3609765531356;
  e36 = x5 + x18 - 0.741937344729377;
  e37 = x6 + x18 - 0.182321556793955;
  e38 = x1 + x19 - 1.91692261218206;
  e39 = x2 + x19 - 1.85629799036563;
  e40 = x3 + x19 - 1.87180217690159;
  e41 = x4 + x19 - 1.48160454092422;
  e42 = x5 + x19 - 0.832909122935104;
  e43 = x6 + x19 - 1.16315080980568;
  e44 = x1 + x20;
  e45 = x2 + x20 - 1.84054963339749;
  e46 = x3 + x20 - 1.68639895357023;
  e47 = x4 + x20 - 2.47653840011748;
  e48 = x5 + x20 - 1.7404661748405;
  e49 = x6 + x20 - 1.82454929205105;
  e50 = x1 + x21 - 1.16315080980568;
  e51 = x2 + x21 - 1.09861228866811;
  e52 = x3 + x21 - 1.25276296849537;
  e53 = x4 + x21 - 1.19392246847243;
  e54 = x5 + x21 - 1.02961941718116;
  e55 = x6 + x21 - 1.22377543162212;
  e56 = x1 + x22 - 0.741937344729377;
  e57 = x2 + x22 - 0.916290731874155;
  e58 = x3 + x22 - 1.43508452528932;
  e59 = x4 + x22 - 1.28093384546206;
  e60 = x5 + x22 - 1.30833281965018;
  e61 = x6 + x22 - 0.78845736036427;
  e62 = 250000.0*exp(x18 - x13) + 150000.0*exp(x19 - x14) ...
    + 180000.0*exp(x20 - x15) + 160000.0*exp(x21 - x16) ...
    + 120000.0*exp(x22 - x17) - 6000.0;
  e63 = x1 - 0.693147180559945*b29 - 1.09861228866811*b35   - 1.38629436111989*b41;
  e64 = x2 - 0.693147180559945*b30 - 1.09861228866811*b36     - 1.38629436111989*b42;
  e65 = x3 - 0.693147180559945*b31 - 1.09861228866811*b37     - 1.38629436111989*b43;
  e66 = x4 - 0.693147180559945*b32 - 1.09861228866811*b38     - 1.38629436111989*b44;
  e67 = x5 - 0.693147180559945*b33 - 1.09861228866811*b39      - 1.38629436111989*b45;
  e68 = x6 - 0.693147180559945*b34 - 1.09861228866811*b40     - 1.38629436111989*b46;
  e69 = b23 + b29 + b35 + b41 - 1.0;
  e70 = b24 + b30 + b36 + b42 - 1.0;
  e71 = b25 + b31 + b37 + b43 - 1.0;
  e72 = b26 + b32 + b38 + b44 - 1.0;
  e73 = b27 + b33 + b39 + b45 - 1.0;
  e74 = b28 + b34 + b40 + b46 - 1.0;

% Rename constraints from GAMS format to fit MIDACO format
  g(1) = e63;
  g(2) = e64;
  g(3) = e65;
  g(4) = e66;
  g(5) = e67;
  g(6) = e68;
  g(7) = e69;
  g(8) = e70;
  g(9) = e71;
  g(10) = e72;
  g(11) = e73;
  g(12) = e74;
  g(13) = -e62;
  g(14) = e2;
  g(15) = e3;
  g(16) = e4;
  g(17) = e5;
  g(18) = e6;
  g(19) = e7;
  g(20) = e8;
  g(21) = e9;
  g(22) = e10;
  g(23) = e11;
  g(24) = e12;
  g(25) = e13;
  g(26) = e14;
  g(27) = e15;
  g(28) = e16;
  g(29) = e17;
  g(30) = e18;
  g(31) = e19;
  g(32) = e20;
  g(33) = e21;
  g(34) = e22;
  g(35) = e23;
  g(36) = e24;
  g(37) = e25;
  g(38) = e26;
  g(39) = e27;
  g(40) = e28;
  g(41) = e29;
  g(42) = e30;
  g(43) = e31;
  g(44) = e32;
  g(45) = e33;
  g(46) = e34;
  g(47) = e35;
  g(48) = e36;
  g(49) = e37;
  g(50) = e38;
  g(51) = e39;
  g(52) = e40;
  g(53) = e41;
  g(54) = e42;
  g(55) = e43;
  g(56) = e44;
  g(57) = e45;
  g(58) = e46;
  g(59) = e47;
  g(60) = e48;
  g(61) = e49;
  g(62) = e50;
  g(63) = e51;
  g(64) = e52;
  g(65) = e53;
  g(66) = e54;
  g(67) = e55;
  g(68) = e56;
  g(69) = e57;
  g(70) = e58;
  g(71) = e59;
  g(72) = e60;
  g(73) = e61;
  
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%   END OF FILE   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
