-
Notifications
You must be signed in to change notification settings - Fork 0
/
optimal_cycle_case2.m
143 lines (142 loc) · 6.72 KB
/
optimal_cycle_case2.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
% clear data and figure
clc;
clear;
close all;
%
load(".\data\parameter2.mat")
% economic parameter
p=6.0;
c=4.0;
h=0.02;
A=100;
%% true parameter
% order cycle to be evaluated
T_eval = (1:0.1:60)';
T_interval=[1,60];
% profit corresponding to simulated parameters
profit_simu = profit(d,theta,lambda,p,c,h,A,T_eval);
% optimal order cycle corresponding to simulated parameters
T_simu_optimal = optimal_cycle(d,theta,lambda,p,c,h,A,T_interval);
% optimal order quantity corresponding to estimated parameters
Q_simu_optimal=T2Q(d,theta,lambda,T_simu_optimal);
% optimal profit corresponding to simulated parameters
profit_simu_optimal = profit(d,theta,lambda,p,c,h,A,T_simu_optimal);
%
syms T;
profit_syms = profit(d,theta,lambda,p,c,h,A,T);
profit_simu_der1=diff(profit_syms,1);
% T_optimal=vpasolve(profit_der1==0,T,T_interval);
profit_simu_der2=diff(profit_syms,2);
matlabFunction(profit_simu_der1,"File","profit_simu_derivative1");
matlabFunction(profit_simu_der2,"File","profit_simu_derivative2");
profit_simu_der1=profit_simu_derivative1(T_eval);
profit_simu_der2=profit_simu_derivative2(T_eval);
%% profit_appro
% profit corresponding to simulated parameters
profit_approx_value = profit_approx(d,theta,lambda,p,c,h,A,T_eval);
% optimal order cycle corresponding to simulated parameters
T_approx_optimal = optimal_cycle_approx(d,theta,lambda,p,c,h,A);
% optimal order quantity corresponding to estimated parameters
Q_approx_optimal=T2Q(d,theta,lambda,T_approx_optimal);
% optimal profit corresponding to simulated parameters
profit_approx_optimal = profit(d,theta,lambda,p,c,h,A,T_approx_optimal);
%
syms T;
profit_syms = profit_approx(d,theta,lambda,p,c,h,A,T);
profit_approx_der1=diff(profit_syms,1);
% T_optimal=vpasolve(profit_der1==0,T,T_interval);
profit_approx_der2=diff(profit_syms,2);
matlabFunction(profit_approx_der1,"File","profit_approx_derivative1");
matlabFunction(profit_approx_der2,"File","profit_approx_derivative2");
profit_approx_der1=profit_approx_derivative1(T_eval);
profit_approx_der2=profit_approx_derivative2(T_eval);
%% estimate parameter
% profit corresponding to simulated parameters
profit_est = profit(d_estimate,theta_estimate,lambda_estimate,p,c,h,A,T_eval);
% optimal order cycle corresponding to simulated parameters
T_est_optimal = optimal_cycle(d_estimate,theta_estimate,lambda_estimate,p,c,h,A,T_interval);
% optimal order quantity corresponding to estimated parameters
Q_est_optimal=T2Q(d_estimate,theta_estimate,lambda_estimate,T_est_optimal);
% optimal profit corresponding to simulated parameters
profit_est_optimal = profit(d_estimate,theta_estimate,lambda_estimate,p,c,h,A,T_est_optimal);
%
syms T;
profit_syms = profit(d_estimate,theta_estimate,lambda_estimate,p,c,h,A,T);
profit_est_approx_der1=diff(profit_syms,1);
% T_optimal=vpasolve(profit_der1==0,T,T_interval);
profit_est_approx_der2=diff(profit_syms,2);
matlabFunction(profit_est_approx_der1,"File","profit_est_derivative1");
matlabFunction(profit_est_approx_der2,"File","profit_est_derivative2");
profit_est_der1=profit_est_derivative1(T_eval);
profit_est_der2=profit_est_derivative2(T_eval);
%%
% profit corresponding to simulated parameters
profit_est_approx = profit_approx(d_estimate,theta_estimate,lambda_estimate,p,c,h,A,T_eval);
% optimal order cycle corresponding to simulated parameters
T_est_approx_optimal = optimal_cycle_approx(d_estimate,theta_estimate,lambda_estimate,p,c,h,A);
% optimal order quantity corresponding to estimated parameters
Q_est_approx_optimal=T2Q(d_estimate,theta_estimate,lambda_estimate,T_est_approx_optimal);
% optimal profit corresponding to simulated parameters
profit_est_approx_optimal = profit(d_estimate,theta_estimate,lambda_estimate,p,c,h,A,T_est_approx_optimal);
%
syms T;
profit_syms = profit_approx(d_estimate,theta_estimate,lambda_estimate,p,c,h,A,T);
profit_est_approx_der1=diff(profit_syms,1);
% T_optimal=vpasolve(profit_der1==0,T,T_interval);
profit_est_approx_der2=diff(profit_syms,2);
matlabFunction(profit_est_approx_der1,"File","profit_est_approx_derivative1");
matlabFunction(profit_est_approx_der2,"File","profit_est_approx_derivative2");
profit_est_approx_der1=profit_est_approx_derivative1(T_eval);
profit_est_approx_der2=profit_est_approx_derivative2(T_eval);
%% plot
figure('unit','centimeters','position',[5,5,30,10],'PaperPosition',[5,5,30,10],'PaperSize',[30,10])
tile=tiledlayout(1,3,'Padding','Compact');
nexttile
%
plot(T_eval,profit_simu,'LineStyle','-','LineWidth',1.5)
hold on;
plot(T_eval,profit_approx_value,'LineStyle','-','LineWidth',1.5)
plot(T_eval,profit_est,'LineStyle','-','LineWidth',1.5)
plot(T_eval,profit_est_approx,'LineStyle','-','LineWidth',1.5)
%
plot(T_simu_optimal,profit_simu_optimal,'LineStyle','none','Marker','*','MarkerSize',8,'Color',[0, 114, 189]/255)
plot(T_approx_optimal,profit_approx_optimal,'LineStyle','none','Marker','*','MarkerSize',8,'Color',[217, 83, 25]/255)
plot(T_est_optimal,profit_est_optimal,'LineStyle','none','Marker','*','MarkerSize',8,'Color',[237, 177, 32]/255)
plot(T_est_approx_optimal,profit_est_approx_optimal,'LineStyle','none','Marker','*','MarkerSize',8,'Color',[126, 47, 142]/255)
%
xlabel({'Hour'},'FontSize',14)
ylabel(['Profit'],'FontSize',14)
title({'(a) Profit'},'FontSize',16)
set(gca,'FontName','Book Antiqua','FontSize',12) % ,'Xlim',[-0.5,7.5],'Ylim',[0,850]
legends=["Profit for true parameters",...
"Approximate profit for true parameters",...
"Profit for estimated parameters",...
"Approximate profit for estimated parameters",...
];
legend(legends,'location','southwest','FontSize',6,'NumColumns',1)
%% plot T vs first derivative of profit
nexttile
plot(T_eval,profit_simu_der1,'LineStyle','-','LineWidth',1.5)
hold on
plot(T_eval,profit_approx_der1,'LineStyle','-','LineWidth',1.5)
plot(T_eval,profit_est_der1,'LineStyle','-','LineWidth',1.5)
plot(T_eval,profit_est_approx_der1,'LineStyle','-','LineWidth',1.5)
xlabel({'Hour'},'FontSize',14)
ylabel(['First derivative of profit'],'FontSize',14)
title({'(b) First derivative of profit'},'FontSize',16)
set(gca,'FontName','Book Antiqua','FontSize',12) % ,'Xlim',[-0.5,7.5],'Ylim',[0,850]
%% second derivative of profit corresponding to simulated parameters
nexttile
plot(T_eval,profit_simu_der2,'LineStyle','-','LineWidth',1.5)
hold on
plot(T_eval,profit_approx_der2,'LineStyle','-','LineWidth',1.5)
plot(T_eval,profit_est_der2,'LineStyle','-','LineWidth',1.5)
plot(T_eval,profit_est_approx_der2,'LineStyle','-','LineWidth',1.5)
xlabel({'Hour'},'FontSize',14)
ylabel(['First derivative of profit'],'FontSize',14)
title({'(b) First derivative of profit'},'FontSize',16)
set(gca,'FontName','Book Antiqua','FontSize',12) % ,'Xlim',[-0.5,7.5],'Ylim',[0,850]
% save figure
savefig(gcf,'.\figure\case2_optimization.fig')
exportgraphics(gcf,'.\figure\case2_optimization.pdf')
%exportgraphics(gcf,'F:\博士\Grey4inventorydynamics\manuscript4\figure\case2_optimization.pdf')