✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,matlab项目合作可私信。
🍎个人主页:Matlab科研工作室
🍊个人信条:格物致知。
更多Matlab仿真内容点击👇
智能优化算法 神经网络预测 雷达通信 无线传感器
信号处理 图像处理 路径规划 元胞自动机 无人机 电力系统
⛄ 内容介绍
⛄ 完整代码
clc;
clear;
close all
Kf =[23.5, 23.5, 23, 23.5,22.5, 23, 23, 22.5, 24, 23, 21.5, 21.5, 21, 21.5, 21];
Bf =[0.75, 0.75, 0.8, 0.75, 0.85, 0.8, 0.8, 0.85, 0.7, 0.8, 0.85, 0.85, 0.9, 0.85, 0.9];
c = [];
%% 定义目标函数的系数
for t = 1:9
c=[c;Kf'];
end
%% 限定 求解的自变量 为正整数
intcon=1:135;
lb=zeros(135,1); % 自变量的下限, >= 0
%% 定义约束条件的系数矩阵
a1 = [ones(1,15),zeros(1,15*8)];
a2 = [zeros(1,15),ones(1,15),zeros(1,15*7)];
a3 = [zeros(1,15*2),ones(1,15),zeros(1,15*6)];
a4 = [zeros(1,15*3),ones(1,15),zeros(1,15*5)];
a5 = [zeros(1,15*4),ones(1,15),zeros(1,15*4)];
a6 = [zeros(1,15*5),ones(1,15),zeros(1,15*3)];
a7 = [zeros(1,15*6),ones(1,15),zeros(1,15*2)];
a8 = [zeros(1,15*7),ones(1,15),zeros(1,15)];
a9 = [zeros(1,15*8),ones(1,15)];
D = 720;
b1 = [-D.*Bf,zeros(1,15*8)];
b2 = [zeros(1,15),-D.*Bf,zeros(1,15*7)];
b3 = [zeros(1,15*2),-D.*Bf,zeros(1,15*6)];
b4 = [zeros(1,15*3),-D.*Bf,zeros(1,15*5)];
b5 = [zeros(1,15*4),-D.*Bf,zeros(1,15*4)];
b6 = [zeros(1,15*5),-D.*Bf,zeros(1,15*3)];
b7 = [zeros(1,15*6),-D.*Bf,zeros(1,15*2)];
b8 = [zeros(1,15*7),-D.*Bf,zeros(1,15)];
b9 = [zeros(1,15*8),-D.*Bf];
Z = [1,0,1,1,1;0,1,1,1,1;1,0,0,1,1;1,1,0,1,1;0,0,0,1,1;0,0,1,1,1;0,1,0,1,1;1,0,0,0,1;1,1,1,1,1;1,1,0,0,1;1,1,0,1,0;0,1,1,1,0;0,1,0,1,0;1,1,1,1,0;1,0,0,1,0];
g2 =repmat([-D*Z(:,1)'.*Bf],1, 9);
g3 =repmat([-D*Z(:,2)'.*Bf],1, 9);
g4 =repmat([-D*Z(:,3)'.*Bf],1, 9);
g5 =repmat([-D*Z(:,4)'.*Bf],1, 9);
g6 =repmat([-D*Z(:,5)'.*Bf],1, 9);
a=[a1;a2;a3;a4;a5;a6;a7;a8;a9;b1;b2;b3;b4;b5;b6;b7;b8;b9;g2;g3;g4;g5;g6];
%% 定义约束条件 不等式右边的值
St = 6*ones(9,1);
yt = [1710;2250;2700;2790;2745;2700;2745;2790;1170];
yg = [4320;2159;2159;6481;6481];
b = [St;-yt;-yg];
%% 执行intlinprog,求解约束最优化问题
[x,fval]=intlinprog(c,intcon,a,b,[],[],lb);
xx = reshape(x,15,9);
disp(xx);
%% 堆叠柱状图
X = 1:9;
Y = xx';
a=bar(X,Y,0.4,'stacked');%绘制
%% 设置堆叠柱状图的颜色
set(a(1),'facecolor',[1, 0, 0]);
set(a(2),'facecolor',[0, 1, 0]);
set(a(3),'facecolor',[0, 0, 1]);
set(a(4),'facecolor',[0.5, 0.5, 0.5]);
set(a(5),'facecolor',[0.98, 0.75, 0.00]);
set(a(6),'facecolor',[0.85, 0.84, 0.5]);
set(a(7),'facecolor',[0.26, 0.45, 0.77]);
set(a(8),'facecolor',[0, 0.33, 0.64]);
set(a(9),'facecolor',[0.89, 0, 0.57]);
set(a(10),'facecolor',[0.9, 0.75, 0.00]);
set(a(11),'facecolor',[0.85, 0.84, 0.86]);
set(a(12),'facecolor',[0.26, 0.45, 0.77]);
set(a(13),'facecolor',[0.21, 0.33, 0.64]);
set(a(14),'facecolor',[0.89, 0.88, 0.57]);
set(a(15),'facecolor',[0.98, 0.75, 0.00]);
legend(a,'f1','f2','f3','f4','f5','f6','f7','f8','f9','f10','f11','f12','f13','f14','f15','location','southoutside','orientation','horizontal');
xlabel('时段'),
ylabel('不同类型列车开行数量/列')
⛄ 运行结果
⛄ 参考文献
❤️部分理论引用网络文献,若有侵权联系博主删除
❤️ 关注我领取海量matlab电子书和数学建模资料