# 基于分布式ADMM算法的考虑碳排放交易的电力系统优化调度研究（matlab代码）

## 1 主要内容

• 目标函数

• 计算步骤

• 节点系统

FileName = 'SCUC_dat/DDOPF118.txt'; %Corresponding to the 118-bus system in literature [7]；对应文献[7]中的118-bus system

%             FileName = 'SCUC_dat/SCUC6.txt';    %Corresponding to the 6-bus System;对应文中6bus例子
%             FileName = 'SCUC_dat/SCUC30.txt'; %Corresponding to the 30-bus System;对应文中30bus例子
%             FileName = 'SCUC_dat/SCUC6-2.txt';  %Corresponding to the 6-bus System in literature [7];对应文献[7]中的6-bus system
%             FileName = 'SCUC_dat/SCUC1062-2.txt';  %Corresponding to the 1062-bus System;对应文中1062-bus例子
%             FileName = 'SCUC_dat/RTS48.txt'; %Corresponding to the RTS-48 bus system.The test system can obtain from [44];对应文中RTS0-48 bus例子

## 2 部分代码

if isequal(k,1) %第一次形成p_t并记下对应的区间即可
p_t_index = []; %存储p_t中每行在XJ中的索引,第一列为初始索引，第二列为结束索引,第三列为行索引
seta_t_index = []; %存储seta_t中每行在XJ中的索引,第一列为初始索引，第二列为结束索引,第三列为行索引
for i = 1:size(allNodes,1)
bus_sequence_index = find(ismember(SCUC_data.busUnits.bus_sequence,allNodes(i,1))==1); %allNodes(i,1)在SCUC_data.busUnits.bus_sequence上的索引
P_start_index = (PbusUnitsNumber(i,1) - PbusUnitsNumber(1,1) + i - 1); %allNodes(i,1)对应变量P前面的所有变量P和θ的总数量
Seta_start_index = (PbusUnitsNumber(i+1,1) - PbusUnitsNumber(1,1) + i - 1); %allNodes(i,1)对应变量θ前面的所有变量P和θ的总数量
if ~isempty(bus_sequence_index) %The bus with unit. 节点上有发电机
for j = 1:size(SCUC_data.busUnits.unitIndex{bus_sequence_index,1},1)
p_t(units_number,:) = XJ(P_start_index*T + (j-1)*T + 1:P_start_index*T + (j-1)*T + T);%P
p_t_index(units_index,1) = P_start_index*T + (j-1)*T + 1;
p_t_index(units_index,2) = P_start_index*T + (j-1)*T + T;
p_t_index(units_index,3) = units_number;
units_number = units_number + 1;
units_index = units_index + 1;
end
else %The bus without unit.节点上没有发电机
p_t(units_number,:) = XJ(P_start_index*T + 1:P_start_index*T + T);%P
units_number = units_number + 1;
end
seta_t(i,:) = XJ(Seta_start_index*T + 1:Seta_start_index*T + T);%θ
seta_t_index(i,1) = Seta_start_index*T + 1;
seta_t_index(i,2) = Seta_start_index*T + T;
seta_t_index(i,3) = i;
end
else  %按照第一次记下的变量顺序即可
p_t = zeros(partitionData.PIUnitsNumber{end}-partitionData.PIUnitsNumber{1},T);
seta_t = zeros(size(seta_t_index,1),T);
for i = 1:size(p_t_index,1)
p_t(p_t_index(i,3),:) = XJ(p_t_index(i,1):p_t_index(i,2));
end
for i = 1:size(seta_t_index,1)
seta_t(seta_t_index(i,3),:) = XJ(seta_t_index(i,1):seta_t_index(i,2));
end
end

elseif isequal(includeDR,'yes')
PINumber = partitionData.PINumber;
EINumber = partitionData.EINumber;
piecewiseNumber = SCUC_data.elasticBus.piecewiseNumber; %分段函数分的段数
K = SCUC_data.elasticBus.N;%弹性节点数量
dr_t = zeros(K,T); %弹性负荷变量dr
hr_t = zeros(piecewiseNumber,T,K); %辅助变量Hr,第一个参数对应分段数，第二个参数对应时段，第三个参数对应节点编号
%按照片区顺序
for i = 1:n
Dindex = 2*(PINumber{i+1}-1)*T + (EINumber{i}-1)*(piecewiseNumber+1)*T; %+2为考虑碳排放的两个变量
Hindex = Dindex + T;
%取dr和hr
for j = 1:EINumber{i+1}-EINumber{i}
%dr的行按照partitionData.allElasticityNodes中节点编号的顺序
dr_t(EINumber{i}-1+j,:) = XJ((j-1)*(piecewiseNumber+1)*T+1+Dindex:(j-1)*(piecewiseNumber+1)*T+T+Dindex); %dr
for r = 1:piecewiseNumber
hr_t(r,:,EINumber{i}-1+j) = XJ((j-1)*(piecewiseNumber+1)*T+(r-1)*T+1+Hindex:(j-1)*(piecewiseNumber+1)*T+(r-1)*T+T+Hindex); %hr
end
end
end

if isequal(k,1)
p_t_index = []; %存储p_t中每行在XJ中的索引,第一列为初始索引，第二列为结束索引,第三列为行索引
seta_t_index = []; %存储seta_t中每行在XJ中的索引,第一列为初始索引，第二列为结束索引,第三列为行索引
%按照片区顺序
for i = 1:n
Pindex = 2*(PINumber{i}-1)*T + (EINumber{i}-1)*(piecewiseNumber+1)*T; %+2为考虑碳排放的两个变量
Dindex = 2*(PINumber{i+1}-1)*T + (EINumber{i}-1)*(piecewiseNumber+1)*T; %+2为考虑碳排放的两个变量
Hindex = Dindex + T;
%取P和θ
for j = 1:PINumber{i+1}-PINumber{i}
%xx的行按照partitionData.allNodes(即allNodes)中节点编号的顺序
p_t(PINumber{i}-1+j,:) = XJ(2*(j-1)*T+1+Pindex:2*(j-1)*T+T+Pindex);%P
seta_t(PINumber{i}-1+j,:) = XJ(2*(j-1)*T+T+1+Pindex:2*(j-1)*T+2*T+Pindex);%θ
p_t_index(PINumber{i}-1+j,1) = 2*(j-1)*T+1+Pindex;
p_t_index(PINumber{i}-1+j,2) = 2*(j-1)*T+T+Pindex;
p_t_index(PINumber{i}-1+j,3) = PINumber{i}-1+j;
seta_t_index(PINumber{i}-1+j,1) = 2*(j-1)*T+T+1+Pindex;
seta_t_index(PINumber{i}-1+j,2) = 2*(j-1)*T+2*T+Pindex;
seta_t_index(PINumber{i}-1+j,3) = PINumber{i}-1+j;
end
end
else  %按照第一次记下的变量顺序即可
p_t = zeros(size(p_t_index,1),T);
seta_t = zeros(size(seta_t_index,1),T);
for i = 1:size(p_t_index,1)
p_t(p_t_index(i,3),:) = XJ(p_t_index(i,1):p_t_index(i,2));
end
for i = 1:size(seta_t_index,1)
seta_t(seta_t_index(i,3),:) = XJ(seta_t_index(i,1):seta_t_index(i,2));
end
end

else
dr_t = []; %弹性负荷变量dr
hr_t = []; %辅助变量Hr
for i = 1:N
p_t(i,:) = XJ((i-1)*2*T+1:(i-1)*2*T+T);%P
seta_t(i,:) = XJ((i-1)*2*T+T+1:(i-1)*2*T+2*T);%θ
end
end

## 3 程序结果

|
3天前
|

6 0
|
5天前
|

13 2
|
20天前
|

Raft算法是一种用于分布式系统中复制日志一致性管理的算法。它通过选举领导者来协调日志复制，确保所有节点数据一致。算法包括心跳机制、选举过程、日志复制和一致性保证。当领导者失效时，节点会重新选举，保证高可用性。Raft易于理解和实现，提供强一致性，常用于分布式数据库和协调服务。作者小米分享了相关知识，鼓励对分布式系统感兴趣的读者进一步探索。
98 0
|
1月前
|

|
1月前
|

21 0
|
1月前
|

26 0
|
1月前
|

25 1
|
1月前

78 1
|
1月前
|

45 0
|
1月前
|

26 1