% MATH 4/5794: Optimization Modeling

% EXAMPLES: H. Greenberg - Example 1, Capital Investment

%                          Example 2, Production

%                          Example 3, Network Flow

%                          Example 4, Transportation

% Created:      January 18, 2005

 

function [x,y,z] = introexharvey(exnum)

 

switch exnum

   case 1

% Example 1 - H. Greenberg Capital Investment

      A = zeros(1,5);

% Matrix A

      A(1,:) = [1 1 1 1 1];

% Left and right endpoint of the extremes of fuzzy right-hand sides

      b(1) = 100000;

% Obj function coefficients - since MATLAB minimizes, need negative to maximize

      c = [-1;-2;-3;-4;-5];

      for i=1:5

         % lower bound, upper bound

         vlb(i,1) = 0;

         vub(i,1) = 100000;

      end

      plusminus = -1;

      Aeq = [];

      beq = [];

%    

case 2

% Example 2 - H. Greenberg Production

   A = zeros(7,4);

% Matrix A - MATLAB's inequalities are all <= for for >= use negative

   A(1,:) = [-1  0  0  0];

   A(2,:) = [-1 -1  0  0];

   A(3,:) = [-1 -1 -1  0];

   A(4,:) = [-1 -1 -1 -1];

   A(5,:) = [ 1 -1  0  0];

   A(6,:) = [ 0  1 -1  0];

   A(7,:) = [ 0  0  1 -1];

% Left and right endpoint of the extremes of fuzzy right-hand sides

   b(1,1) = -5;

   b(2,1) = -11;

   b(3,1) = -19;

   b(4,1) = -25;

   b(5,1) =  0;

   b(6,1) =  0;

   b(7,1) =  0;

% Cost coefficients, since minimizing with matlab, need no sign change

   c = [3;7;4;7];

   for i=1:4

      % starting point

      vlb(i,1) = 0;

   end

   plusminus = 1;

   vub = [];

   Aeq = [];

   beq = [];

%

case 3

% Example 3 - H. Greenberg Network Flow

   Aeq = zeros(3,6);

% Matrix Aeq - MATLAB's equalities

   Aeq(1,:) = [ 1  0 -1 -1  0  0];

   Aeq(2,:) = [ 0  1  1  0 -1  0];

   Aeq(3,:) = [ 0  0  0  1  1 -1];

% Right-hand sides

   beq(1,1) = 0;

   beq(2,1) = 0;

   beq(3,1) = 0;

% Cost coefficients, since minimizing with matlab, need no sign change

   c = [0;0;0;0;0;-1];

   for i=1:6

% starting point

      vlb(i,1) = 0;

   end

% Capacities along the arcs

   vub(1,1) = 4;

   vub(2,1) = 3;

   vub(3,1) = 1;

   vub(4,1) = 2;

   vub(5,1) = 3;

   vub(6,1) = 100;

   plusminus = -1;

   A = [];

   b = [];

case 4

% Example 4 - H. Greenberg Tranportation with integer variables

case 5

% Example 5 - H. Greenberg Diet Problem

   A = zeros(4,3);

% Matrix A - MATLAB's inequalities are all <= for for >= use negative

   A(1,:) = [ -2   -3   -7];

   A(2,:) = [ -1   -1    0];

   A(3,:) = [ -5   -3    0];

   A(4,:) = [-0.6 -0.25 -1];

% Left and right endpoint of the extremes of fuzzy right-hand sides

   b(1,1) = -1250;

   b(2,1) = -250;

   b(3,1) = -900;

   b(4,1) = -232.5;

% Cost coefficients, since minimizing with matlab, need no sign change

   c = [41;35;96];

   for i=1:3

% starting point

      vlb(i,1) = 0;

   end

% Capacities along the arcs

   plusminus = 1;

   Aeq = [];

   beq = [];

   vub = [];

%  

otherwise

   out = 'exnum not valid'

   exnum

end   % end case of exnum

% Call the lp solver

x = linprog(c,A,b,Aeq,beq,vlb,vub);

soln = 'The solution is: ';

soln

x

% Objective function value

obj = 'Objective function value is: ';

z = plusminus*(c'*x)

% Constraint values

if exnum == 3

   A = Aeq;

   b = beq;

end %end if

cons = 'The excess on the constraints at the solution are: ';

y = b - A*x

out = 'solution is:';

************************************************************

************************************************************

************ Multiple Sclerosis Scab Detection *************

************************************************************

************************************************************

% MATH 4/5794: Optimization Modeling

% EXAMPLES: W. A. Lodwick -  Example 1, Multiple Sclerosis Scab Detection

%                            Example 2, Multiple Sclerosis Scab Detection

%                            Example 3, Multiple Sclerosis Scab Detection

%                            Example 4, Multiple Sclerosis Scab Detection                           

% Created:      January 20, 2005

 

function [x,z,c] = classdemo2(exnum)

% options=optimset('Gradobj','on');

% x(1): Echo time

% x(2): Pulse repetition time

   x0(1,1)  = 0;

   x0(2,1)  = 0;

   vlb(1,1) = 10.00000001;

   vlb(2,1) = 100;

   vub(1,1) = 200;

   vub(2,1) = 3000;

 

% Call the nlp solver

[x,z] =fmincon('introwalobj',x0,[],[],[],[],vlb,vub,'introwalcon',[],exnum);

'The solution is: '

x

% Obj function value - since minimizing to obtain maximum, need negative to

%                      get the correct maximum

z = -z;

'Objective function value is: '

z

% Constraints - how close the solution is to satisfying the constraints

[c,ceq] = introwalcon(x,exnum);

'Constraints are'

c = -c;

******************************************************************************

% introwalcon

% Created      January 20, 2005

% This m-file defines the various examples models

% computes the constraints c(x) <= 0

function [c,ceq] = introwalobj(x,exnum);

switch exnum

case 1

% Example 1 - Multiple Sclerosis Scab Detection Model 12

% Multiple Sclerosis Spin Echo

   A1 = (1-2*exp(-(x(2) - (x(1)/2))/688)+exp(-x(2)/688))*exp(-x(1)/113);

% White Matter Spin Echo

   A2 = 0.89*(1-2*exp(-(x(2) - (x(1)/2))/370)+exp(-x(2)/370))*exp(-x(1)/70);

% Cranial/Spinal Fluid Spin Echo

   A3 = 1.15*(1-2*exp(-(x(2) - (x(1)/2))/2850)+exp(-x(2)/285))*exp(-x(1)/372);

% Alpha

   c(1,1) = -sqrt((A1 - A2)^2)+ 0.004;

   c(2,1) = -sqrt((A1 - A3)^2)+ 0.004;

   ceq = [];

case 2

% Example 2 - Multiple Sclerosis Scab Detection Model 13

% Multiple Sclerosis Spin Echo

   A1 = (1-2*exp(-(x(2) - (x(1)/2))/688)+exp(-x(2)/688))*exp(-x(1)/113);

% White Matter Spin Echo

   A2 = 0.89*(1-2*exp(-(x(2) - (x(1)/2))/370)+exp(-x(2)/370))*exp(-x(1)/70);

% Cranial/Spinal Fluid Spin Echo

   A3 = 1.15*(1-2*exp(-(x(2) - (x(1)/2))/2850)+exp(-x(2)/285))*exp(-x(1)/372);

% Alpha

   c(1,1) = -sqrt((A1 - A2)^2) + 0.004;

   c(2,1) = -sqrt((A1 - A3)^2) + 0.004;

   c(3,1) = -sqrt((A2 - A3)^2) + 0.004;

   ceq = [];

case 3

% Example 3 - Multiple Sclerosis Scab Detection Model 22

% Multiple Sclerosis Spin Echo

   A1 = (1-2*exp(-(x(2) - (x(1)/2))/688)+exp(-x(2)/688))*exp(-x(1)/113);

% White Matter Spin Echo

   A2 = 0.89*(1-2*exp(-(x(2) - (x(1)/2))/370)+exp(-x(2)/370))*exp(-x(1)/70);

% Cranial/Spinal Fluid Spin Echo

   A3 = 1.15*(1-2*exp(-(x(2) - (x(1)/2))/2850)+exp(-x(2)/285))*exp(-x(1)/372);

% Alpha

   c(1,1) = -(A1 - A2)^2 + 0.004;

   c(2,1) = -(A1 - A3)^2 + 0.004;

   ceq = [];

case 4

% Example 4 - Multiple Sclerosis Scab Detection Model 23

% Multiple Sclerosis Spin Echo

   A1 = (1-2*exp(-(x(2) - (x(1)/2))/688)+exp(-x(2)/688))*exp(-x(1)/113);

% White Matter Spin Echo

   A2 = 0.89*(1-2*exp(-(x(2) - (x(1)/2))/370)+exp(-x(2)/370))*exp(-x(1)/70);

% Cranial/Spinal Fluid Spin Echo

   A3 = 1.15*(1-2*exp(-(x(2) - (x(1)/2))/2850)+exp(-x(2)/285))*exp(-x(1)/372);

% Alpha

   c(1,1) = -(A1 - A2)^2 + 0.004;

   c(2,1) = -(A1 - A3)^2 + 0.004;

   c(3,1) = -(A2 - A3)^2 + 0.004;

   ceq = [];

otherwise

   'exnum not valid'

   exnum

end   % end case of exnum

*******************************************************************************

% introwalobj

% Created      January 20, 2005

% This m-file defines the various examples models

% f is the function objective function and g is the gradient if f

function f = introwalobj(x,exnum);

switch exnum

  

case 1

% Example 1 - Multiple Sclerosis Scab Detection Model 12

% Multiple Sclerosis Spin Echo

   A1 = (1-2*exp(-(x(2) - (x(1)/2))/688)+exp(-x(2)/688))*exp(-x(1)/113);

% White Matter Spin Echo

   A2 = 0.89*(1-2*exp(-(x(2) - (x(1)/2))/370)+exp(-x(2)/370))*exp(-x(1)/70);

% Alpha

   alpha = sqrt(x(1)-10)/x(2);

% We're maximizing so we need to negate the minimum since MATLAB does minima

   f = -(sqrt(A1^2) + sqrt(A2^2))*alpha;

case 2

% Example 2 - Multiple Sclerosis Scab Detection Model 13

% Multiple Sclerosis Spin Echo

   A1 = (1-2*exp(-(x(2) - (x(1)/2))/688)+exp(-x(2)/688))*exp(-x(1)/113);

% White Matter Spin Echo

   A2 = 0.89*(1-2*exp(-(x(2) - (x(1)/2))/370)+exp(-x(2)/370))*exp(-x(1)/70);

% Cranial/Spinal Fluid Spin Echo

   A3 = 1.15*(1-2*exp(-(x(2) - (x(1)/2))/2850)+exp(-x(2)/285))*exp(-x(1)/372);

% Alpha

   alpha = sqrt(x(1)-10)/x(2);

% We're maximizing so we need to negate the minimum since MATLAB does minima

   f = -(sqrt(A1^2) + sqrt(A2^2) + sqrt(A3^2))*alpha;

case 3

% Example 3 - Multiple Sclerosis Scab Detection Model 22

% Multiple Sclerosis Spin Echo

   A1 = (1-2*exp(-(x(2) - (x(1)/2))/688)+exp(-x(2)/688))*exp(-x(1)/113);

% White Matter Spin Echo

   A2 = 0.89*(1-2*exp(-(x(2) - (x(1)/2))/370)+exp(-x(2)/370))*exp(-x(1)/70);

% Alpha

   alpha = sqrt(x(1)-10)/x(2);

% We're maximizing so we need to negate the minimum since MATLAB does minima

   f = -(A1^2 + A2^2)*alpha;

case 4

% Example 4 - Multiple Sclerosis Scab Detection Model 23

   A1 = (1-2*exp(-(x(2) - (x(1)/2))/688)+exp(-x(2)/688))*exp(-x(1)/113);

% White Matter Spin Echo

   A2 = 0.89*(1-2*exp(-(x(2) - (x(1)/2))/370)+exp(-x(2)/370))*exp(-x(1)/70);

% Cranial/Spinal Fluid Spin Echo

   A3 = 1.15*(1-2*exp(-(x(2) - (x(1)/2))/2850)+exp(-x(2)/285))*exp(-x(1)/372);

% Alpha

   alpha = sqrt(x(1)-10)/x(2);

% We're maximizing so we need to negate the minimum since MATLAB does minima

   f = -(A1^2 + A2^2 + A3^2)*alpha;

otherwise

   'exnum not valid'

   exnum

end   % end case of exnum