问题一
模型假设
略
符号定义
源代码_1
model:
title NJUCM第二次作业;
sets:
Per_day_person/1..7/:number;
endsets
min = @sum(Per_day_person(i) : number(i));
@for(Per_day_person(i)|i#le#4 :
@sum(Per_day_person(j)|j#le#i : number(j)) + @sum(Per_day_person(k)|k#ge#i+3#and#k#le#7 : number(k)) > 50);
@sum(Per_day_person(i)|i#le#5 : number(i)) > 80;
@for(Per_day_person(i)|i#ge#6 #and# i#le#7 :
@sum(Per_day_person(j)|j#ge#i-4#and#j#le#i : number(j)) > 90);
@for(Per_day_person(i) :
@gin(number(i)));
end
源代码_2
model:
min = x1 + x2 + x3 + x4 + x5 + x6 + x7;
x1+x4+x5+x6+x7>50;
x1+x2+x5+x6+x7>50;
x1+x2+x3+x6+x7>50;
x1+x2+x3+x4+x7>50;
x1+x2+x3+x4+x5>80;
x2+x3+x4+x5+x6>90;
x3+x4+x5+x6+x7>90;
@gin(x1);
@gin(x2);
@gin(x3);
@gin(x4);
@gin(x5);
@gin(x6);
@gin(x7);
end
源代码_3
model:
sets:
f/1..7/:x;
endsets
min = @sum(f(i) : x(i));
x(1) + x(4) + x(5) + x(6) + x(7) > 50;
x(1) + x(2) + x(5) + x(6) + x(7) > 50;
x(1) + x(2) + x(3) + x(6) + x(7) > 50;
x(1) + x(2) + x(3) + x(4) + x(7) > 50;
x(1) + x(2) + x(3) + x(4) + x(5) > 80;
x(2) + x(3) + x(4) + x(5) + x(6) > 90;
x(3) + x(4) + x(5) + x(6) + x(7) > 90;
@for(f(i) :
@gin(x(i)));
end
问题二
建模前的准备
首先使用matlab软件,绘制出每次投资法对应的结投时间图。
https://blog.csdn.net/m0_53347750/article/details/123295425
这是我另外一个回答中,提到甘特图的画法
function NJUCM_2()
clear;
%% 基础设置
axis([0, 20, 0, 5.5]);
set(gca, 'xtick', 0 : 1 : 20);
set(gca, 'ytick', 0 : 1 : 10.5);
xlabel('购买年与结投年'), ylabel('证券种类');
title('证券投资年份');
Number_securities = 15;
Number_task = 15;
%% 对应坐标
X_start_time = [1 11 10 1 5 16 1 16 5 1 17 4 1 18 3];
X_duration_time = [10 2 10 4 2 4 15 2 15 16 2 16 17 2 17];
Y_start_time = [1 1 2 3 3 4 5 5 6 7 7 8 9 9 10];
N_job_id = [1 1 1 2 2 2 3 3 3 4 4 4 5 5 5];
rec = [0 0 0 0 ];
color=['r','g','b','c','m'];
%% 绘图
for i = 1 : Number_securities
rec(1) = X_start_time(i);
rec(2) = Y_start_time(i) + 0.7;
rec(3) = X_duration_time(i);
rec(4) = 0.6;
txt=sprintf('(%d,%d)', N_job_id(i)+1, X_duration_time(i));
rectangle('Position',rec,'LineWidth',0.5,'LineStyle','-','FaceColor',color(N_job_id(i)+1));
text(X_start_time(i)+0.2,(Y_start_time(i)+1),txt,'FontWeight','Bold','FontSize',18);
end
end
符号定义
目标函数和约束条件
因为使得收益最大,那就要在第20年前最近的那一次,投资得到的收益要最大。
约束条件:
1、政府及代办机构的证券总共至少要购进400万。
2、信用等级不超过1.49。
3、平均到期期限不超过5年。
4、每次投资额都是上次投资得到的金额加上收益额。
5、部分年份不能投资
源代码
model:
title 投资问题;
sets:
Security_information/1..5/:Credit_dating, Maturity, Total_revenue, Rate;
Year/1..20/:Investing_congress;
Link(Year, Security_information):Investment_approach;
endsets
data:
Credit_dating = 2 2 1 1 5;
Maturity = 9 15 4 3 2;
Total_revenue = 0.5249 1 0.1699 0.1184 0.0712;
Rate = 0 0.5 0.5 0.5 0;
enddata
max = @sum(Link(i, j)|i#ge#20-Maturity(j)#and#i#le#21-Maturity(j) :
Investment_approach(i, j) + Investment_approach(i, j) * Total_revenue(j) * (1 - Rate(j)));
@sum(Link(i, j)|i#le#2 :
Investment_approach(i, j)) = 1000;
@sum(Link(i, j) :
Investment_approach(i, j) * Credit_dating(j)) /
@sum(Link(i, j) :
Investment_approach(i, j)) < 1.49;
@sum(Link(i, j) :
Investment_approach(i, j) * Maturity(j)) /
@sum(Link(i, j) :
Investment_approach(i, j)) < 5;
@for(Link(i, j)|i+Maturity(j)#ge#21:
Investment_approach(i, j) = 0);
@sum(Link(i, j)|j#ge#2#and#j#le#4 :
Investment_approach(i, j)) > 400;
@for(Year(i)|i#ge#2 :
@sum(Security_information(j) : Investment_approach(i, j))
=
@sum(Security_information(j)|i#gt#Maturity(j) :
Investment_approach(i - Maturity(j), j) + Investment_approach(i - Maturity(j), j) * Total_revenue(j) * (1 - Rate(j))));
end
运行不出来,学长说是软件的问题,等后面有时间我尝试用matlab做一下。