Trying to find the answer to a linear programming optimization problem...this is the code I have so far having a hard time smoothing out all the errors...any help would be great
Afficher commentaires plus anciens
clc
%%====== Setup =========
S = [[3000 1000 2000];[1000 1000 4000];[2000 500 3000]];
sol = [];
c = S(:,3);
B = S; B(:,3) = [];
[sr sc] = size(B);
Axes = eye(sc);
%% ============ Find Interceptions ===============
A = [B(1,:);B(2,:)];
b = [c(1);c(2)];
sol = [sol linsolve(A,b)];
A = [B(1,:);B(3,:)];
b =[c(1);c(3)];
sol = [sol linsolve(A,b)];
A = [B(2,:);B(3,:)];
b = [c(2);c(3)];
sol = [sol linsolve(A,b)];
%% === Check for axes intersections ==
for i=1:sc
for j=1:sr
A = [Axes(i,:);B(j,:)];
b = [0;c(j)];
sol = [sol linsolve(A,b)];
[plotxyaxes(A,b)];
end
end
%% === Find corner points of feasible
%% === region ======
[r c] = size(sol);
feasible = []; tolerance = 0.0;
for i=1:c
v = (sol(:,i));
x = v(1); y = v(2); z = v(3);
if (3000*x + 1000*y + 2000*z) <= 24000 + tolerance ...
&& (1000*x + 1000*y + 4000*z) <= 16000 + tolerance && ...
(2000*x + 500*y + 3000*z) <= 48800 + tolerance
feasible = [feasible sol(:,i)];
end
end
disp(feasible)
%% ====== Find optimum ==========================
n = 10000;
opt = 100; xopt = 0; yopt = 0;
for i=1:n
x = 3 * rand(1,1)+1;
y = 3 * rand(1,1)+1;
if ((3000*x + 1000*y + 2000*z) <= 24000) && ((1000*x + 1000*y + 4000*z) <= 16000) && ((2000*x + 500*y + 3000*z) <= 48800)
z = (600*x + 400*y) / 500;
if (z < opt)
opt = z;
xopt = x;
yopt = y;
end
end
end
disp(opt);
disp(xopt);
disp(yopt);
Réponses (0)
Catégories
En savoir plus sur Solver Outputs and Iterative Display dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!