调用Tstart.m,EVtype.m,SOC.m,Lrem.m脚本,生成200辆车的数据参数:包括Tstart.m脚本中的Ts,EVtype脚本中的car_param,SOC.m脚本中的S0,Lrem.m脚本中的Lre。随机从200辆车中抽取一辆车,定义9个充电方案Project,包括3个参数:1.充电类型(Ch_type):Ch_no,Ch_slow,Ch_fast;2.充电成本(Ch_cost):Ch_cost=E*Ch_charge/Pt_price;3.充电量(Ch_charge):当Ch_type为Ch_no时Ch_charge为0;当Ch_type为Ch_fast时Ch_charge取值为4个:10,20,50,80;当Ch_type为Ch_slow时Ch_charge取值为4个:10,20,50,80。其中,当Ch_type为Ch_no时Pt_price为0,当Ch_type为Ch_slow时Pt_price为2.37,当Ch_type为Ch_fast时Pt_price为5.52;计算9个方案的后悔值R,包括3个参数:初始剩余电量(S0),电费成本(Ch_cost),未来出行满足度(Travel_sat):未来出行满足度等于(S0+Ch_charge)E/PELre。然后编写函数计算方案i的后悔值R,计算公式1为:Ri⟶jm=ln(1+exp(βm(xjm-xim))),其中,S0的β值为0.2,Ch_cost的β值为0.3,Travel_sat的β值为-0.1;计算公式2为:Ri=∑j≠i,j=1J∑m=1MRi⟶jm,计算公式3为Pi=exp(-Rj)/∑j=1Jexp(-Rj),输出第i辆车的9种充电方案及其对应的后悔值R,输出内容为(i,Ch_type,Ch_charge,Ch_cost,Travel_sat, Ri,Pi)。用matlab代码描述这一过程。
时间: 2024-02-12 11:09:42 浏览: 82
以下是代码实现:
```matlab
% 调用四个脚本生成200辆车的数据参数
addpath(genpath('脚本文件夹路径'));
load car_param.mat;
load Ts.mat;
load S0.mat;
load Lre.mat;
% 随机抽取一辆车
car_num = randi([1,200]);
% 定义9个充电方案
Ch_type = {'Ch_no', 'Ch_slow', 'Ch_fast', 'Ch_slow', 'Ch_fast', 'Ch_slow', 'Ch_fast', 'Ch_slow', 'Ch_fast'};
Ch_cost = zeros(1, 9);
Ch_charge = [0, 10, 10, 20, 20, 50, 50, 80, 80];
Pt_price = [0, 2.37, 5.52, 2.37, 5.52, 2.37, 5.52, 2.37, 5.52];
Travel_sat = zeros(1, 9);
% 计算后悔值R
R = zeros(1, 9);
beta = [0.2, 0.3, -0.1];
for i = 1:9
if strcmp(Ch_type{i}, 'Ch_no')
Ch_cost(i) = 0;
else
Ch_cost(i) = car_param(car_num, 4) * Ch_charge(i) / Pt_price(i);
end
Travel_sat(i) = (S0(car_num) + Ch_charge(i)) * car_param(car_num, 3) / Lre(car_num);
for j = 1:9
if j ~= i
xj = [S0(car_num), Ch_cost(j), Travel_sat(j)];
xi = [S0(car_num), Ch_cost(i), Travel_sat(i)];
Rijm = 0;
for m = 1:3
Rijm = Rijm + log(1 + exp(beta(m) * (xj(m) - xi(m))));
end
R(i) = R(i) + Rijm;
end
end
end
% 计算Pi
P = exp(-R) / sum(exp(-R));
% 输出结果
for i = 1:9
fprintf('(%d,%s,%d,%.2f,%.2f,%.2f,%.2f)\n', car_num, Ch_type{i}, Ch_charge(i), Ch_cost(i), Travel_sat(i), R(i), P(i));
end
```
其中,需要将脚本文件夹路径替换为实际路径。输出结果格式为(i,Ch_type,Ch_charge,Ch_cost,Travel_sat,Ri,Pi)。
阅读全文