You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mycode/LPej1_3.m

41 lines
1.6 KiB

clc; clear; close all; format long g;
prob=optimproblem;
x=optimvar('x',9,1,'LowerBound',0,'Type','integer');
p=[0.25,0.35,0.50];
r=[1.25,2.00,2.80];
ot=[5,10,0;7,9,12;6,8,0;4,0,11;7,0,0];
total=1000:200:3000;
odp=[300/6000,321/10000,250/4000,783/7000,200/4000];
X=[];
Q=[];
for i=1:length(total)
% prob.Objective=(ot(1,1)*ones(1,3)*x(1:3)+ot(1,2)*x(7))*odp(1)+(ot(2,1)*ones(1,3)*x(4:6)+ot(2,2)*x(8)+ot(2,3)*x(9))*odp(2)+(ot(3,1)*(x(1)+x(4))+ot(3,2)*(x(7)+x(8)))*odp(3)+(ot(4,1)*(x(2)+x(5))+ot(4,3)*x(9))*odp(4)+(ot(5,1)*(x(3)+x(6)))*odp(5)-(r(1)-p(1))*ones(1,6)*x(1:6)-(r(2)-p(2))*ones(1,2)*x(7:8)-(r(3)-p(3))*x(9);
dp1=(ot(1,1)*ones(1,3)*x(1:3)+ot(1,2)*x(7))*odp(1);
dp2=(ot(2,1)*ones(1,3)*x(4:6)+ot(2,2)*x(8)+ot(2,3)*x(9))*odp(2);
dp3=(ot(3,1)*(x(1)+x(4))+ot(3,2)*(x(7)+x(8)))*odp(3);
dp4=(ot(4,1)*(x(2)+x(5))+ot(4,3)*x(9))*odp(4);
dp5=(ot(5,1)*(x(3)+x(6)))*odp(5);
dp=dp1+dp2+dp3+dp4+dp5;
prob.Objective=dp-(r(1)-p(1))*ones(1,6)*x(1:6)-(r(2)-p(2))*ones(1,2)*x(7:8)-(r(3)-p(3))*x(9);
prob.Constraints.con1=p(1)*ones(1,6)*x(1:6)+p(2)*ones(1,2)*x(7:8)+p(3)*x(9)+dp<=total(i);%总费用
prob.Constraints.con2=ot(1,1)*ones(1,3)*x(1:3)+ot(1,2)*x(7)<=6000;%A1
prob.Constraints.con3=ot(2,1)*ones(1,3)*x(4:6)+ot(2,2)*x(8)+ot(2,3)*x(9)<=10000;
prob.Constraints.con4=ot(3,1)*(x(1)+x(4))+ot(3,2)*(x(7)+x(8))<=4000;
prob.Constraints.con5=ot(4,1)*(x(2)+x(5))+ot(4,3)*x(9)<=7000;
prob.Constraints.con6=ot(5,1)*(x(3)+x(6))<=4000;
[sol,fval,flag,out]=solve(prob);
xx=sol.x;
X=[X,xx];
Q=[Q,-fval];
end
plot(total,Q,'*-');