% MATH 4/5794: Optimization Modeling
% EXAMPLES: H. Greenberg - Example 1, Capital Investment
%
Example 2, Production
%
Example 3, Network Flow
%
Example 4, Transportation
% Spring Semester 2005
function [x,y,z] = classdemo1(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;
% Objective
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];
% Left and
right endpoint of the extremes of fuzzy 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: ';
obj
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: ';
cons
y = b - A*x
out = 'solution is:';