【免费】基于SOE算法的多时段随机配电网重构方法

简介: 【免费】基于SOE算法的多时段随机配电网重构方法

1 主要内容

该程序是完全复现《Switch Opening and Exchange Method for Stochastic Distribution Network Reconfiguration》,也是一个开源代码,网上有些人卖的还挺贵,本次免费分享给大家,代码主要做的是一个通过配电网重构获取最优网络拓扑的问题,从而有效降低网损,提高经济效益,同时考虑了光伏和负荷的随机性,构建了多时段随机配电网重构模型,考虑到大型网络中计算较为耗时,采用一种基于开断和交换的SOE方法,已获得良好的径向拓扑,采用IEEE多个标准算例进行了测试,更加创新,而且求解的效果更好,结果和论文基本是一致,代码质量非常高,但是子程序比较多,适合有编程经验的同学学习!

2 部分程序

% core programme in decrese_reconfig_33.m   already obtain optimal solution, no need to execute tabu
clear all, clc, close all
addpath('./code')
%% basic setting
tic
fprintf('decrease_reconfig_33_tabu.m \n')
warning('off')
addpath(pathdef)
mpopt = mpoption;
mpopt.out.all = 0; % do not print anything
mpopt.verbose = 0;
version_LODF = 0 % 1: use decrease_reconfig_algo_LODF.m
                                  % 0: use decrease_reconfig_algo.m
candi_brch_bus = []; % candidate branch i added to bus j
% mpc0 = case33;
casei=4
d33zhu_v2
substation_node = 1;        n_bus = 33;
n1 = 3
n2 = 5
n1_down_substation = n1+1;    n2_up_ending = n2;
Branch0 = Branch;
brch_idx_in_loop0 = unique(brch_idx_in_loop(:));
%% original network's power flow (not radial)
% show_biograph(Branch, Bus)
from_to = show_biograph_not_sorted(Branch, substation_node, 0); 
mpc = generate_mpc(Bus, Branch, n_bus);
res_orig = runpf(mpc, mpopt);
losses = get_losses(res_orig.baseMVA, res_orig.bus, res_orig.branch);
loss0 = sum(real(losses));
fprintf('case33_tabu: original loop network''s loss is %.5f \n\n', loss0)
% for each branch in a loop, 
% if open that branch does not cause isolation, check the two ending buses 
% of that branch for connectivity, realized by shortestpath or conncomp
% calculate the lowest loss increase, print out the sorted loss increase 
% open the branch with lowest loss increase
% stop criterion: number of buses - number of branches = 1
%% ------------------------ Core algorithm ------------------------%%
ff0 = Branch(:, 1);   ff = ff0;
tt0 = Branch(:, 2);   tt = tt0;
t1 = toc;
if version_LODF
    [Branch] = decrease_reconfig_algo_LODF(Bus, Branch, brch_idx_in_loop, ...
        ff0, tt0, substation_node, n_bus, loss0); %%%  core algorithm
else
    [Branch] = decrease_reconfig_algo(Bus, Branch, brch_idx_in_loop, ff0, tt0, ...
        substation_node, n_bus, loss0); %%%  core algorithm
end
t2 = toc;
time_consumption.core = t2 - t1
% output of core algorithm
show_biograph = 0;
from_to = show_biograph_not_sorted(Branch(:, [1 2]), substation_node, ...
        0);
from_to0 = from_to;
mpc = generate_mpc(Bus, Branch, n_bus);
res_pf_dec = runpf(mpc, mpopt);
losses = get_losses(res_pf_dec.baseMVA, res_pf_dec.bus, res_pf_dec.branch);
loss0_dec = sum(real(losses));  % 
fprintf('case33_tabu: radial network obtained by my core algorithm''s loss is %.5f \n\n', loss0_dec)
Branch_loss_record = [];
% record Branch and loss
Branch_loss_record.core.Branch = Branch;
Branch_loss_record.core.loss = loss0_dec;
%% prepare force open branches for tabu: branch_idx_focused
[branch_idx_focused] = get_branch_idx_focused_for_tabu( ...
    from_to, Branch0, Branch, substation_node, brch_idx_in_loop0, n_bus, ...
    n1_down_substation, n2_up_ending);
%% ------------------------ Tabu algorithm ------------------------%%
% run the core program for each upstream branch connected to the idx_force_open
% idx_considered = [35 69]
% for iter = idx_considered
for iter = 1:length(branch_idx_focused)
    fprintf('iter=%d/%d\n', iter, length(branch_idx_focused));
    Branch = Branch0;
    Branch(branch_idx_focused(iter), :) = [];
    
    ff0 = Branch(:, 1);   ff = ff0;
    tt0 = Branch(:, 2);   tt = tt0;
    
    brch_idx_in_loop = brch_idx_in_loop0;
    idx_tmp = find(brch_idx_in_loop == branch_idx_focused(iter));
    if isempty(idx_tmp)
    else
        brch_idx_in_loop(idx_tmp) = [];
        brch_idx_in_loop(idx_tmp:end) = brch_idx_in_loop(idx_tmp:end)-1;
    end
    t1 = toc;
    %%------------------- core algorithm in Tabu loop--------------------%%    
    if version_LODF
        [Branch] = decrease_reconfig_algo_LODF(Bus, Branch, brch_idx_in_loop, ...
            ff0, tt0, substation_node, n_bus, loss0); %%%  core algorithm
    else
        [Branch] = decrease_reconfig_algo(Bus, Branch, brch_idx_in_loop, ff0, tt0, ...
            substation_node, n_bus, loss0); %%%  core algorithm
    end
    t2 = toc;    
    time_consumption.tabu(iter) = t2-t1;
    from_to = show_biograph_not_sorted(Branch(:, [1 2]), substation_node, ...
        show_biograph); %%% show figure, take time
    mpc = generate_mpc(Bus, Branch, n_bus);
    t1 = toc;
    res_pf = runpf(mpc, mpopt);
    t2 = toc;    
    losses = get_losses(res_pf.baseMVA, res_pf.bus, res_pf.branch);
    lossi = sum(real(losses)) % loss = 0.5364
    loss_tabu(iter,1) = lossi;
    yij_dec = generate_yij_from_Branch(Branch, Branch0);
    % record Branch and loss
    Branch_loss_record.tabu(iter,1).Branch = Branch; 
    Branch_loss_record.tabu(iter,1).loss = lossi;
    
    [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
      VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
%     Vm = res_pf.bus(:, VM)';
%     Va = res_pf.bus(:, VA)';
%     ending_bus = find_ending_node(Branch, substation_node);
%     [ending_bus'; Vm(ending_bus)]; 
    
    %% ---------------------one open and one close---------------------%%   
    % prepare nodes_focused for one_open_one_close
    t1 = toc;
    [nodes_focused] = get_nodes_focused_o1c1( ...
        from_to, Branch, Branch0, substation_node, brch_idx_in_loop, ...
        n1_down_substation, n2_up_ending);
    loss_before_switch0 = lossi;
    [record_o1c1_loss_dec, loss_after_switch_combine_two_o1c1, Branch_loss] = ...
        one_open_one_close(nodes_focused, Bus, Branch0, Branch, from_to, ...
        substation_node, n_bus, loss_before_switch0);
    t2 = toc;
    time_consumption.tabu_o1c1(iter) = t2-t1;
    % record Branch and loss
    Branch_loss_record.tabu_o1c1_dec{iter}.Branch = Branch_loss.Branch_o1c1_dec; 
%     Branch_loss_record.tabu_o1c1_dec(iter,1).Branch = Branch_loss.Branch_o1c1_dec; 
    Branch_loss_record.tabu_o1c1_dec{iter}.loss = Branch_loss.loss_o1c1_dec; 
    Branch_loss_record.tabu_combine_2_o1c1_dec{iter}.Branch = ...
        Branch_loss.Branch_after_switch_combine_two_o1c1; 
    Branch_loss_record.tabu_combine_2_o1c1_dec{iter}.loss = ...
        Branch_loss.loss_after_switch_combine_two_o1c1;  
    min_loss_o1c1 = min(record_o1c1_loss_dec(:,1));
    fprintf('case33_tabu: minimum loss obtained after ''one open and one close'': %.5f\n', ...
        min_loss_o1c1);
    min_loss_combine_two_o1c1 = 1e9;
    fprintf('case33_tabu: loss obtained after combine two ''one open and one close'': \n')
    for i = 1:length(loss_after_switch_combine_two_o1c1)
        temp = min(loss_after_switch_combine_two_o1c1{i});
        if temp %.5f \n', temp);
    end    
    fprintf('case33_tabu: minimum loss obtained after combine two ''one open and one close'': %.5f \n', ...
        min_loss_combine_two_o1c1)  
    
    %% ---------------------two open and two close---------------------%%
    flag_2o2c = 0
    if flag_2o2c == 1
        t1 = toc;
        loss_before_switch0 = lossi;
        [record_o2c2_loss_dec, loss_after_switch_combine_two_o2c2] = ...
            two_open_two_close(nodes_focused, Bus, Branch0, Branch, from_to, ...
            substation_node, n_bus, loss_before_switch0);
        t2 = toc;
        time_consumption.tabu_o2c2(iter) = t2-t1;
        
        min_loss_o2c2 = min(record_o2c2_loss_dec(:,1));
        fprintf('case33_tabu: minimum loss obtained after ''two open and two close'': %.5f\n', ...
            min_loss_o2c2);
        min_loss_combine_two_o2c2 = 1e9;
        fprintf('case33_tabu: loss obtained after combine two ''two open and two close'': \n')
        for i = 1:length(loss_after_switch_combine_two_o2c2)
            temp = min(loss_after_switch_combine_two_o2c2{i});
            if temp %.5f \n', temp);
        end
        fprintf('case33_tabu: minimum loss obtained after combine two ''two open and two close'': %.5f \n', ...
            min_loss_combine_two_o2c2)  
        res_save{iter}.min_loss_o2c2 = min_loss_o2c2;
        res_save{iter}.min_loss_combine_two_o2c2 = min_loss_combine_two_o2c2;
    end
    res_save{iter}.yij_dec = yij_dec;
    res_save{iter}.Branch = Branch;
    res_save{iter}.lossi = lossi;    
    res_save{iter}.record_o1c1_loss_dec = record_o1c1_loss_dec;
    res_save{iter}.min_loss_o1c1 = min_loss_o1c1;
    res_save{iter}.min_loss_combine_two_o1c1 = min_loss_combine_two_o1c1;
    
%     file_name = ['case33_yij_Branch_', num2str(idx_force_open(iter)), '.mat'];
%     save(file_name, 'yij_dec', 'Branch', 'lossi');
    file_name = ['id1_case33_yij_Branch', '.mat'];
    save(file_name, 'res_save', 'branch_idx_focused', 'Branch_loss_record', ...
        'time_consumption');   
    
end
file_name = ['id1_case33_yij_Branch', '.mat'];
save(file_name, 'res_save', 'branch_idx_focused', 'Branch_loss_record', ...
    'time_consumption');
% find_all_losses(Branch_loss_record);
fprintf('case33_tabu: losses obtained after applying tabu strategy: \n') % 0.28343  zjp 2018-1-18
fprintf('%.5f \n', loss_tabu)
fprintf('----- min: %.5f -----\n', min(loss_tabu))
min_loss = 1e9;
for i = 1:length(res_save)
    if min_loss>res_save{i}.min_loss_o1c1 
        min_loss = res_save{i}.min_loss_o1c1 ;
    end
    if min_loss>res_save{i}.min_loss_combine_two_o1c1 
        min_loss = res_save{i}.min_loss_combine_two_o1c1 ;
    end
end  
min_loss_o1c1 = min_loss
if flag_2o2c == 1
    min_loss = 1e9;
    for i = 1:length(res_save)
        if min_loss>res_save{i}.min_loss_o2c2 
            min_loss = res_save{i}.min_loss_o2c2 ;
        end
        if min_loss>res_save{i}.min_loss_combine_two_o2c2 
            min_loss = res_save{i}.min_loss_combine_two_o2c2 ;
        end
    end  
    min_loss_o2c2 = min_loss
end

3 部分模型级文献结果

4 下载链接

相关文章
|
21天前
|
机器学习/深度学习 算法 数据挖掘
K-means聚类算法是机器学习中常用的一种聚类方法,通过将数据集划分为K个簇来简化数据结构
K-means聚类算法是机器学习中常用的一种聚类方法,通过将数据集划分为K个簇来简化数据结构。本文介绍了K-means算法的基本原理,包括初始化、数据点分配与簇中心更新等步骤,以及如何在Python中实现该算法,最后讨论了其优缺点及应用场景。
66 4
|
2月前
|
存储 算法 Java
解析HashSet的工作原理,揭示Set如何利用哈希算法和equals()方法确保元素唯一性,并通过示例代码展示了其“无重复”特性的具体应用
在Java中,Set接口以其独特的“无重复”特性脱颖而出。本文通过解析HashSet的工作原理,揭示Set如何利用哈希算法和equals()方法确保元素唯一性,并通过示例代码展示了其“无重复”特性的具体应用。
52 3
|
19天前
|
存储 算法 安全
SnowflakeIdGenerator-雪花算法id生成方法
SnowflakeIdGenerator-雪花算法id生成方法
20 1
|
23天前
|
JSON 算法 数据挖掘
基于图论算法有向图PageRank与无向图Louvain算法构建指令的方式方法 用于支撑qwen agent中的统计相关组件
利用图序列进行数据解读,主要包括节点序列分析、边序列分析以及结合节点和边序列的综合分析。节点序列分析涉及节点度分析(如入度、出度、度中心性)、节点属性分析(如品牌、价格等属性的分布与聚类)、节点标签分析(如不同标签的分布及标签间的关联)。边序列分析则关注边的权重分析(如关联强度)、边的类型分析(如管理、协作等关系)及路径分析(如最短路径计算)。结合节点和边序列的分析,如子图挖掘和图的动态分析,可以帮助深入理解图的结构和功能。例如,通过子图挖掘可以发现具有特定结构的子图,而图的动态分析则能揭示图随时间的变化趋势。这些分析方法结合使用,能够从多个角度全面解读图谱数据,为决策提供有力支持。
|
2月前
|
算法
基于粒子群算法的分布式电源配电网重构优化matlab仿真
本研究利用粒子群算法(PSO)优化分布式电源配电网重构,通过Matlab仿真验证优化效果,对比重构前后的节点电压、网损、负荷均衡度、电压偏离及线路传输功率,并记录开关状态变化。PSO算法通过迭代更新粒子位置寻找最优解,旨在最小化网络损耗并提升供电可靠性。仿真结果显示优化后各项指标均有显著改善。
|
2月前
|
算法 索引
HashMap扩容时的rehash方法中(e.hash & oldCap) == 0算法推导
HashMap在扩容时,会创建一个新数组,并将旧数组中的数据迁移过去。通过(e.hash & oldCap)是否等于0,数据被巧妙地分为两类:一类保持原有索引位置,另一类索引位置增加旧数组长度。此过程确保了数据均匀分布,提高了查询效率。
45 2
|
2月前
|
搜索推荐 Shell
解析排序算法:十大排序方法的工作原理与性能比较
解析排序算法:十大排序方法的工作原理与性能比较
72 9
|
2月前
|
存储 算法 Java
数据结构与算法学习八:前缀(波兰)表达式、中缀表达式、后缀(逆波兰)表达式的学习,中缀转后缀的两个方法,逆波兰计算器的实现
前缀(波兰)表达式、中缀表达式和后缀(逆波兰)表达式的基本概念、计算机求值方法,以及如何将中缀表达式转换为后缀表达式,并提供了相应的Java代码实现和测试结果。
113 0
数据结构与算法学习八:前缀(波兰)表达式、中缀表达式、后缀(逆波兰)表达式的学习,中缀转后缀的两个方法,逆波兰计算器的实现
|
2月前
|
机器学习/深度学习 人工智能 开发框架
【AI系统】AI 学习方法与算法现状
在人工智能的历史长河中,我们见证了从规则驱动系统到现代机器学习模型的转变。AI的学习方法基于深度神经网络,通过前向传播、反向传播和梯度更新不断优化权重,实现从训练到推理的过程。当前,AI算法如CNN、RNN、GNN和GAN等在各自领域取得突破,推动技术进步的同时也带来了更大的挑战,要求算法工程师与系统设计师紧密合作,共同拓展AI技术的边界。
110 1
|
4月前
|
JavaScript 算法 前端开发
JS算法必备之String常用操作方法
这篇文章详细介绍了JavaScript中字符串的基本操作,包括创建字符串、访问特定字符、字符串的拼接、位置查找、大小写转换、模式匹配、以及字符串的迭代和格式化等方法。
JS算法必备之String常用操作方法