├── README.md ├── calculation_119.m ├── ga.m ├── mc.m ├── para119.mat ├── performance.png └── valid_119.m /README.md: -------------------------------------------------------------------------------- 1 | Genetic Algorithm Network Reconfiguration 2 | ===================== 3 | 4 | Genetic algorithm for reducing the power loss in an electrical network consisting out of 119 nodes. 5 | Based on the paper: 6 | Zhang, Dong, Zhengcai Fu, and Liuchun Zhang. "An improved TS algorithm for loss-minimum reconfiguration in large-scale distribution systems." Electric Power Systems Research 77.5 (2007): 685-694. 7 | 8 | The network has binary encoded 2^132 search options, sequence encoded 1.44*10^18 search options. Consequently the search space is much to large to brute-force the optimal network configuration within a reasonable time span. 9 | Therefore we reconfigure the network by using a genetic algorithm and see if we can achieve the lowest power loss in the network within a reasonable time frame. The result is compared with a simple Monte Carlo algorithm. 10 | 11 | The genetic algorithm is based on two functions that use the matlab matpower package: http://www.pserc.cornell.edu/matpower/ We assume the package directory is situated in the working directory. we used version 4.1. Both the functions, valid_119.m & calculation_119.m are from Kaifeng Yang. 12 | 13 | Main result 14 | ----------- 15 | 16 | ![Result](https://raw.githubusercontent.com/sirvincent/ga_network_reconfiguration/master/performance.png) 17 | The genetic algorithm found the lowest power loss achievable in the electrical network; 869.7272 kW within 70 seconds. 18 | 19 | Future Work 20 | ----------- 21 | A report will be uploaded explaining in detail the found results and the genetic algorithm implemented. 22 | 23 | 24 | Special Thanks To 25 | ------------ 26 | Kaifang Yang for the functions and Prof. Dr. T. Bäck for giving the course Evolutionary Algorithm at Leiden University. 27 | The genetic algorithm and monte carlo algorithm were part of an assignment for the Evolutionary Algorithms course. 28 | -------------------------------------------------------------------------------- /calculation_119.m: -------------------------------------------------------------------------------- 1 | %% This function is to calculate power loss and minimum voltage for 119 nodes test system 2 | % Input: 3 | % - chorm 4 | % Output 5 | % - power_loss 6 | % - min_v 7 | % Kaifeng Yang, Feb. 19, 2014 8 | % This function need the platform of MATPOWER by Ray D. Zimmerman, Carlos E. Murillo-Sánchez & Deqiang (David) Gan 9 | % http://www.pserc.cornell.edu//matpower/ 10 | function power_loss = calculation_119(chorm) 11 | mpc.version = '2'; 12 | 13 | %%----- Power Flow Data -----%% 14 | %% system MVA base 15 | mpc.baseMVA = 1; 16 | 17 | %% bus data 18 | % bus_i type Pd Qd Gs Bs area Vm Va baseKV zone Vmax Vmin 19 | mpc.bus = [ 20 | 1 3 0 0 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 21 | 2 1 0.133840000000000 0.101140000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 22 | 3 1 0.0162140000000000 0.0112920000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 23 | 4 1 0.0343150000000000 0.0218450000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 24 | 5 1 0.0730160000000000 0.0636020000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 25 | 6 1 0.144200000000000 0.0686040000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 26 | 7 1 0.104470000000000 0.0617250000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 27 | 8 1 0.0285470000000000 0.0115030000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 28 | 9 1 0.0875600000000000 0.0510730000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 29 | 10 1 0.198200000000000 0.106770000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 30 | 11 1 0.146800000000000 0.0759950000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 31 | 12 1 0.0260400000000000 0.0186870000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 32 | 13 1 0.0521000000000000 0.0232200000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 33 | 14 1 0.141900000000000 0.117500000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 34 | 15 1 0.0218700000000000 0.0287900000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 35 | 16 1 0.0333700000000000 0.0264500000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 36 | 17 1 0.0324300000000000 0.0252300000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 37 | 18 1 0.0202340000000000 0.0119060000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 38 | 19 1 0.156940000000000 0.0785230000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 39 | 20 1 0.546290000000000 0.351400000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 40 | 21 1 0.180310000000000 0.164200000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 41 | 22 1 0.0931670000000000 0.0545940000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 42 | 23 1 0.0851800000000000 0.0396500000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 43 | 24 1 0.168100000000000 0.0951780000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 44 | 25 1 0.125110000000000 0.150220000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 45 | 26 1 0.0160300000000000 0.0246200000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 46 | 27 1 0.0260300000000000 0.0246200000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 47 | 28 1 0.594560000000000 0.522620000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 48 | 29 1 0.120620000000000 0.0591170000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 49 | 30 1 0.102380000000000 0.0995540000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 50 | 31 1 0.513400000000000 0.318500000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 51 | 32 1 0.475250000000000 0.456140000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 52 | 33 1 0.151430000000000 0.136790000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 53 | 34 1 0.205380000000000 0.0833020000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 54 | 35 1 0.131600000000000 0.0930820000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 55 | 36 1 0.448400000000000 0.369790000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 56 | 37 1 0.440520000000000 0.321640000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 57 | 38 1 0.112540000000000 0.0551340000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 58 | 39 1 0.0539630000000000 0.0389980000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 59 | 40 1 0.393050000000000 0.342600000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 60 | 41 1 0.326740000000000 0.278560000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 61 | 42 1 0.536260000000000 0.240240000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 62 | 43 1 0.0762470000000000 0.0665620000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 63 | 44 1 0.0535200000000000 0.0397600000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 64 | 45 1 0.0403280000000000 0.0319640000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 65 | 46 1 0.0396530000000000 0.0207580000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 66 | 47 1 0.0661950000000000 0.0423610000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 67 | 48 1 0.0739040000000000 0.0516530000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 68 | 49 1 0.114770000000000 0.0579650000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 69 | 50 1 0.918370000000000 1.20510000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 70 | 51 1 0.210300000000000 0.146660000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 71 | 52 1 0.0666800000000000 0.0566080000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 72 | 53 1 0.0422070000000000 0.0401840000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 73 | 54 1 0.433740000000000 0.283410000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 74 | 55 1 0.0621000000000000 0.0268600000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 75 | 56 1 0.0924600000000000 0.0883800000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 76 | 57 1 0.0851880000000000 0.0554360000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 77 | 58 1 0.345300000000000 0.332400000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 78 | 59 1 0.0225000000000000 0.0168300000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 79 | 60 1 0.0805510000000000 0.0491560000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 80 | 61 1 0.0958600000000000 0.0907580000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 81 | 62 1 0.0629200000000000 0.0477000000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 82 | 63 1 0.478800000000000 0.463740000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 83 | 64 1 0.120940000000000 0.0520060000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 84 | 65 1 0.139110000000000 0.100340000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 85 | 66 1 0.391780000000000 0.193500000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 86 | 67 1 0.0277410000000000 0.0267130000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 87 | 68 1 0.0528140000000000 0.0252570000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 88 | 69 1 0.0668900000000000 0.0387130000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 89 | 70 1 0.467500000000000 0.395140000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 90 | 71 1 0.594850000000000 0.239740000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 91 | 72 1 0.132500000000000 0.0843630000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 92 | 73 1 0.0526990000000000 0.0224820000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 93 | 74 1 0.869790000000000 0.614775000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 94 | 75 1 0.0313490000000000 0.0298170000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 95 | 76 1 0.192390000000000 0.122430000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 96 | 77 1 0.0657500000000000 0.0453700000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 97 | 78 1 0.238150000000000 0.223220000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 98 | 79 1 0.294550000000000 0.162470000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 99 | 80 1 0.485570000000000 0.437920000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 100 | 81 1 0.243530000000000 0.183030000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 101 | 82 1 0.243530000000000 0.183030000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 102 | 83 1 0.134250000000000 0.119290000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 103 | 84 1 0.0227100000000000 0.0279600000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 104 | 85 1 0.0495130000000000 0.0265150000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 105 | 86 1 0.383780000000000 0.257160000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 106 | 87 1 0.0496400000000000 0.0206000000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 107 | 88 1 0.0224730000000000 0.0118060000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 108 | 89 1 0.0629300000000000 0.0429600000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 109 | 90 1 0.0306700000000000 0.0349300000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 110 | 91 1 0.0625300000000000 0.0667900000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 111 | 92 1 0.114570000000000 0.0817480000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 112 | 93 1 0.0812920000000000 0.0665260000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 113 | 94 1 0.0317330000000000 0.0159600000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 114 | 95 1 0.0333200000000000 0.0604800000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 115 | 96 1 0.531280000000000 0.224850000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 116 | 97 1 0.507030000000000 0.367420000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 117 | 98 1 0.0263900000000000 0.0117000000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 118 | 99 1 0.0459900000000000 0.0303920000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 119 | 100 1 0.100660000000000 0.0475720000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 120 | 101 1 0.456480000000000 0.350300000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 121 | 102 1 0.522560000000000 0.449290000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 122 | 103 1 0.408430000000000 0.168460000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 123 | 104 1 0.141480000000000 0.134250000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 124 | 105 1 0.104430000000000 0.0660240000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 125 | 106 1 0.0967930000000000 0.0836470000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 126 | 107 1 0.493920000000000 0.419340000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 127 | 108 1 0.225380000000000 0.135880000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 128 | 109 1 0.509210000000000 0.387210000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 129 | 110 1 0.188500000000000 0.173460000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 130 | 111 1 0.918030000000000 0.898550000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 131 | 112 1 0.305080000000000 0.215370000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 132 | 113 1 0.0543800000000000 0.0409700000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 133 | 114 1 0.211140000000000 0.192900000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 134 | 115 1 0.0670090000000000 0.0533360000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 135 | 116 1 0.162070000000000 0.0903210000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 136 | 117 1 0.0487850000000000 0.0291560000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 137 | 118 1 0.0339000000000000 0.0189800000000000 0 0 1 1 0 11 1 1.05000000000000 0.950000000000000 138 | ]; 139 | %% generator data 140 | % bus Pg Qg Qmax Qmin Vg mBase status Pmax Pmin Pc1 Pc2 Qc1min Qc1max Qc2min Qc2max ramp_agc ramp_10 ramp_30 ramp_q apf 141 | mpc.gen = [ 142 | 1 20 20 100 -100 1 1 1 100 0 0 0 0 0 0 0 0 0 0 0 0; 143 | ]; 144 | 145 | %% branch data 146 | % fbus tbus r x b rateA rateB rateC ratio angle status angmin angmax 147 | mpc.branch =[ 148 | 1 2 0.0002975 0.0001074 0 100 100 100 0 0 1 -360 360 149 | 2 3 0.0002727 0.0000983 0 100 100 100 0 0 1 -360 360 150 | 2 4 0.0003719 0.0001339 0 100 100 100 0 0 1 -360 360 151 | 4 5 0.0001240 0.0004463 0 100 100 100 0 0 1 -360 360 152 | 5 6 0.0001240 0.0004463 0 100 100 100 0 0 1 -360 360 153 | 6 7 0.0001240 0.0001033 0 100 100 100 0 0 1 -360 360 154 | 7 8 0.0001488 0.0001157 0 100 100 100 0 0 1 -360 360 155 | 8 9 0.0001736 0.0005207 0 100 100 100 0 0 1 -360 360 156 | 2 10 0.0013719 0.0011107 0 100 100 100 0 0 1 -360 360 157 | 10 11 0.0009256 0.0006521 0 100 100 100 0 0 1 -360 360 158 | 11 12 0.0015455 0.0025868 0 100 100 100 0 0 1 -360 360 159 | 12 13 0.0011736 0.0012496 0 100 100 100 0 0 1 -360 360 160 | 13 14 0.0014876 0.0009752 0 100 100 100 0 0 1 -360 360 161 | 14 15 0.0012397 0.0003719 0 100 100 100 0 0 1 -360 360 162 | 15 16 0.0013223 0.0014876 0 100 100 100 0 0 1 -360 360 163 | 16 17 0.0012975 0.0014132 0 100 100 100 0 0 1 -360 360 164 | 11 18 0.0018017 0.0023554 0 100 100 100 0 0 1 -360 360 165 | 18 19 0.0009752 0.0015289 0 100 100 100 0 0 1 -360 360 166 | 19 20 0.0013223 0.0016198 0 100 100 100 0 0 1 -360 360 167 | 20 21 0.0009917 0.0015620 0 100 100 100 0 0 1 -360 360 168 | 21 22 0.0009917 0.0006521 0 100 100 100 0 0 1 -360 360 169 | 22 23 0.0116529 0.0059752 0 100 100 100 0 0 1 -360 360 170 | 23 24 0.0024215 0.0011140 0 100 100 100 0 0 1 -360 360 171 | 24 25 0.0010992 0.0008595 0 100 100 100 0 0 1 -360 360 172 | 25 26 0.0014711 0.0011074 0 100 100 100 0 0 1 -360 360 173 | 26 27 0.0014711 0.0011074 0 100 100 100 0 0 1 -360 360 174 | 4 28 0.0001240 0.0002446 0 100 100 100 0 0 1 -360 360 175 | 28 29 0.0000992 0.0002281 0 100 100 100 0 0 1 -360 360 176 | 29 30 0.0009917 0.0022860 0 100 100 100 0 0 1 -360 360 177 | 30 31 0.0017355 0.0020083 0 100 100 100 0 0 1 -360 360 178 | 31 32 0.0009917 0.0004463 0 100 100 100 0 0 1 -360 360 179 | 32 33 0.0014711 0.0019339 0 100 100 100 0 0 1 -360 360 180 | 33 34 0.0014711 0.0019339 0 100 100 100 0 0 1 -360 360 181 | 34 35 0.0012727 0.0013388 0 100 100 100 0 0 1 -360 360 182 | 30 36 0.0015455 0.0021570 0 100 100 100 0 0 1 -360 360 183 | 36 37 0.0010992 0.0008182 0 100 100 100 0 0 1 -360 360 184 | 29 38 0.0027273 0.0016033 0 100 100 100 0 0 1 -360 360 185 | 38 39 0.0025620 0.0016033 0 100 100 100 0 0 1 -360 360 186 | 39 40 0.0010744 0.0016033 0 100 100 100 0 0 1 -360 360 187 | 40 41 0.0023140 0.0012397 0 100 100 100 0 0 1 -360 360 188 | 41 42 0.0097521 0.0070248 0 100 100 100 0 0 1 -360 360 189 | 42 43 0.0034711 0.0020132 0 100 100 100 0 0 1 -360 360 190 | 43 44 0.0022314 0.0008033 0 100 100 100 0 0 1 -360 360 191 | 44 45 0.0028017 0.0010091 0 100 100 100 0 0 1 -360 360 192 | 45 46 0.0022314 0.0014702 0 100 100 100 0 0 1 -360 360 193 | 35 47 0.0017355 0.0011430 0 100 100 100 0 0 1 -360 360 194 | 47 48 0.0009917 0.0006521 0 100 100 100 0 0 1 -360 360 195 | 48 49 0.0012397 0.0008157 0 100 100 100 0 0 1 -360 360 196 | 49 50 0.0012397 0.0008157 0 100 100 100 0 0 1 -360 360 197 | 50 51 0.0019835 0.0013066 0 100 100 100 0 0 1 -360 360 198 | 51 52 0.0009917 0.0006521 0 100 100 100 0 0 1 -360 360 199 | 52 53 0.0033471 0.0012050 0 100 100 100 0 0 1 -360 360 200 | 53 54 0.0033471 0.0012050 0 100 100 100 0 0 1 -360 360 201 | 29 55 0.0032314 0.0011653 0 100 100 100 0 0 1 -360 360 202 | 55 56 0.0033554 0.0012074 0 100 100 100 0 0 1 -360 360 203 | 56 57 0.0033554 0.0012074 0 100 100 100 0 0 1 -360 360 204 | 57 58 0.0058347 0.0045132 0 100 100 100 0 0 1 -360 360 205 | 58 59 0.0027934 0.0010066 0 100 100 100 0 0 1 -360 360 206 | 59 60 0.0027934 0.0010066 0 100 100 100 0 0 1 -360 360 207 | 60 61 0.0017107 0.0006174 0 100 100 100 0 0 1 -360 360 208 | 61 62 0.0020413 0.0073736 0 100 100 100 0 0 1 -360 360 209 | 1 63 0.0002314 0.0003455 0 100 100 100 0 0 1 -360 360 210 | 63 64 0.0009669 0.0016661 0 100 100 100 0 0 1 -360 360 211 | 64 65 0.0021074 0.0007587 0 100 100 100 0 0 1 -360 360 212 | 65 66 0.0017355 0.0006273 0 100 100 100 0 0 1 -360 360 213 | 66 67 0.0031653 0.0011405 0 100 100 100 0 0 1 -360 360 214 | 67 68 0.0041653 0.0027298 0 100 100 100 0 0 1 -360 360 215 | 68 69 0.0033554 0.0012074 0 100 100 100 0 0 1 -360 360 216 | 69 70 0.0079504 0.0062893 0 100 100 100 0 0 1 -360 360 217 | 70 71 0.0013636 0.0004959 0 100 100 100 0 0 1 -360 360 218 | 71 72 0.0025041 0.0009025 0 100 100 100 0 0 1 -360 360 219 | 72 73 0.0025041 0.0009025 0 100 100 100 0 0 1 -360 360 220 | 73 74 0.0017025 0.0011901 0 100 100 100 0 0 1 -360 360 221 | 74 75 0.0019256 0.0006942 0 100 100 100 0 0 1 -360 360 222 | 75 76 0.0048843 0.0014653 0 100 100 100 0 0 1 -360 360 223 | 76 77 0.0010413 0.0003744 0 100 100 100 0 0 1 -360 360 224 | 64 78 0.0046198 0.0030471 0 100 100 100 0 0 1 -360 360 225 | 78 79 0.0015372 0.0010140 0 100 100 100 0 0 1 -360 360 226 | 79 80 0.0015372 0.0010140 0 100 100 100 0 0 1 -360 360 227 | 80 81 0.0021488 0.0011488 0 100 100 100 0 0 1 -360 360 228 | 81 82 0.0012727 0.0012231 0 100 100 100 0 0 1 -360 360 229 | 82 83 0.0019008 0.0010579 0 100 100 100 0 0 1 -360 360 230 | 83 84 0.0020826 0.0008760 0 100 100 100 0 0 1 -360 360 231 | 84 85 0.0014876 0.0012231 0 100 100 100 0 0 1 -360 360 232 | 79 86 0.0013223 0.0015041 0 100 100 100 0 0 1 -360 360 233 | 86 87 0.0016529 0.0019008 0 100 100 100 0 0 1 -360 360 234 | 87 88 0.0013223 0.0032479 0 100 100 100 0 0 1 -360 360 235 | 65 89 0.0055289 0.0019934 0 100 100 100 0 0 1 -360 360 236 | 89 90 0.0021983 0.0010140 0 100 100 100 0 0 1 -360 360 237 | 90 91 0.0021983 0.0010140 0 100 100 100 0 0 1 -360 360 238 | 91 92 0.0021983 0.0010140 0 100 100 100 0 0 1 -360 360 239 | 92 93 0.0021983 0.0010140 0 100 100 100 0 0 1 -360 360 240 | 93 94 0.0019256 0.0009504 0 100 100 100 0 0 1 -360 360 241 | 94 95 0.0040992 0.0011405 0 100 100 100 0 0 1 -360 360 242 | 91 96 0.0016198 0.0014876 0 100 100 100 0 0 1 -360 360 243 | 96 97 0.0016198 0.0014876 0 100 100 100 0 0 1 -360 360 244 | 97 98 0.0015421 0.0010083 0 100 100 100 0 0 1 -360 360 245 | 98 99 0.0006165 0.0026281 0 100 100 100 0 0 1 -360 360 246 | 1 100 0.0005165 0.0002190 0 100 100 100 0 0 1 -360 360 247 | 100 101 0.0012405 0.0019339 0 100 100 100 0 0 1 -360 360 248 | 101 102 0.0011132 0.0007339 0 100 100 100 0 0 1 -360 360 249 | 102 103 0.0019066 0.0009942 0 100 100 100 0 0 1 -360 360 250 | 103 104 0.0036942 0.0013289 0 100 100 100 0 0 1 -360 360 251 | 104 105 0.0013488 0.0004860 0 100 100 100 0 0 1 -360 360 252 | 105 106 0.0027273 0.0008182 0 100 100 100 0 0 1 -360 360 253 | 106 107 0.0012893 0.0004636 0 100 100 100 0 0 1 -360 360 254 | 107 108 0.0031562 0.0011355 0 100 100 100 0 0 1 -360 360 255 | 108 109 0.0013438 0.0004835 0 100 100 100 0 0 1 -360 360 256 | 109 110 0.0031562 0.0011355 0 100 100 100 0 0 1 -360 360 257 | 110 111 0.0020207 0.0007264 0 100 100 100 0 0 1 -360 360 258 | 110 112 0.0017256 0.0006223 0 100 100 100 0 0 1 -360 360 259 | 112 113 0.0019017 0.0006843 0 100 100 100 0 0 1 -360 360 260 | 100 114 0.0050430 0.0018149 0 100 100 100 0 0 1 -360 360 261 | 114 115 0.0015421 0.0010496 0 100 100 100 0 0 1 -360 360 262 | 115 116 0.0030843 0.0020331 0 100 100 100 0 0 1 -360 360 263 | 116 117 0.0033471 0.0030331 0 100 100 100 0 0 1 -360 360 264 | 117 118 0.0040413 0.0036198 0 100 100 100 0 0 1 -360 360 265 | 266 | 46 27 0.0043455 0.0024174 0 100 100 100 0 0 1 -360 360 267 | 17 27 0.0043455 0.0024099 0 100 100 100 0 0 1 -360 360 268 | 8 24 0.0035306 0.0012719 0 100 100 100 0 0 1 -360 360 269 | 54 43 0.0039669 0.0014281 0 100 100 100 0 0 1 -360 360 270 | 62 49 0.0029752 0.0010711 0 100 100 100 0 0 1 -360 360 271 | 37 62 0.0047107 0.0047273 0 100 100 100 0 0 1 -360 360 272 | 9 40 0.0043802 0.0027669 0 100 100 100 0 0 1 -360 360 273 | 58 96 0.0032702 0.0011777 0 100 100 100 0 0 1 -360 360 274 | 73 91 0.0056198 0.0053554 0 100 100 100 0 0 1 -360 360 275 | 88 75 0.0033570 0.0012099 0 100 100 100 0 0 1 -360 360 276 | 99 77 0.0038231 0.0013835 0 100 100 100 0 0 1 -360 360 277 | 108 83 0.0053802 0.0019339 0 100 100 100 0 0 1 -360 360 278 | 105 86 0.0067149 0.0024174 0 100 100 100 0 0 1 -360 360 279 | 110 118 0.0058587 0.0021099 0 100 100 100 0 0 1 -360 360 280 | 25 35 0.0041322 0.0041322 0 100 100 100 0 0 1 -360 360 281 | ]; 282 | 283 | code = [ 284 | 27 26 25 24 23 22 21 20 19 18 11 10 4 28 29 38 39 40 41 42 43 44 45 46 119 285 | 17 16 15 14 13 12 18 19 20 21 22 23 24 25 26 27 120 0 0 0 0 0 0 0 0 286 | 24 23 22 21 20 19 18 11 10 4 5 6 7 8 121 0 0 0 0 0 0 0 0 0 0 287 | 43 42 41 40 39 38 30 31 32 33 34 35 47 48 49 50 51 52 53 54 122 0 0 0 0 288 | 49 48 47 35 34 33 32 31 30 55 56 57 58 59 60 61 62 123 0 0 0 0 0 0 0 289 | 290 | 37 36 30 55 56 57 58 59 60 61 62 124 0 0 0 0 0 0 0 0 0 0 0 0 0 291 | 9 8 7 6 5 28 29 38 39 40 125 0 0 0 0 0 0 0 0 0 0 0 0 0 0 292 | 58 57 56 55 29 28 4 2 63 64 65 89 90 91 96 126 0 0 0 0 0 0 0 0 0 293 | 91 90 89 66 67 68 69 70 71 72 73 127 0 0 0 0 0 0 0 0 0 0 0 0 0 294 | 75 74 73 72 71 70 69 68 67 66 65 78 79 86 87 88 128 0 0 0 0 0 0 0 0 295 | 296 | 99 98 97 96 91 90 89 66 67 68 69 70 71 72 73 74 75 76 77 129 0 0 0 0 0 297 | 83 82 81 80 79 78 64 63 100 101 102 103 104 105 106 107 108 130 0 0 0 0 0 0 0 298 | 86 79 78 64 63 100 101 102 103 104 105 131 0 0 0 0 0 0 0 0 0 0 0 0 0 299 | 110 109 108 107 106 105 104 103 102 101 114 115 116 117 118 132 0 0 0 0 0 0 0 0 0 300 | 25 24 23 22 21 20 19 18 11 10 4 28 29 30 31 32 33 34 35 133 0 0 0 0 0 301 | ]; 302 | 303 | delete_branch = zeros(15,1); 304 | for i = 1:15 305 | delete_branch(i,1) = code(i,chorm(i)); 306 | end 307 | mpc.branch(delete_branch-1,:)=[]; 308 | 309 | 310 | [branch, voltage] = runpf(mpc); 311 | power_loss = real(sum(branch(:,14))+sum(branch(:,16)))*1000; 312 | min_v = 1- real(min(voltage)); 313 | 314 | -------------------------------------------------------------------------------- /ga.m: -------------------------------------------------------------------------------- 1 | function [aopt, fopt] = ga(evalbudget) 2 | % Genetic algorithm to determine the best configuration that minimizes the 3 | % power loss in a power distribution network. 4 | % 5 | % Input is the number of evaluations the algorithm makes 6 | % 7 | % The function returns: 8 | % - aopt: the best found network configuration 9 | % - fopt: the minimal power loss corresponding to the best network configuration aopt 10 | 11 | % The population is encoded into three variables: 12 | % P = {pop_pheno, pop_geno, power_loss} 13 | % where pop_pheno is an integer configuration, pop_geno the corresponding 14 | % bit string representation and power_loss the corresponding lost power 15 | % in kW 16 | 17 | % GA parameters 18 | mu = 20; % population size 19 | pc = 0.9; % crossover probability 20 | pm = 0.01; % mutation probability 21 | k_tourney = ceil(mu/3); % Tournament size 22 | pt = 0.9; % tournament selection probability 23 | npoint = 6; % amount of crossover points 24 | 25 | % Set upperbounds, taken over from valid_119.m 26 | ub = [25;17;15;21;18;12;11;16;12;17;20;18;12;16;20]; 27 | 28 | % Allocate memory for population and new population variables 29 | pheno_len = size(ub, 1); 30 | pop_pheno = zeros(pheno_len, mu); 31 | pop_geno = cell(pheno_len, mu); 32 | power_loss = zeros(1, mu); 33 | Pnew_pheno = zeros(pheno_len, mu); 34 | Pnew_geno = cell(pheno_len, mu); 35 | 36 | 37 | % Load variables of the experiments 38 | load('para119.mat') 39 | 40 | % Add path of matpower4.1 41 | addpath('matpower4.1') 42 | 43 | % Statistics administration 44 | evalcount = 0; 45 | histf = zeros(1, evalbudget); 46 | 47 | % Initialize population 48 | for it = 1:mu 49 | while valid_119(pop_pheno(:,it)) == 0 50 | % Generate random individual, decode to phenotype, and evaluate 51 | for itP = 1:pheno_len 52 | pop_pheno(itP,it) = randi(ub(itP), 1); 53 | end 54 | end 55 | % Change to bit string for genotype 56 | pop_geno(:,it) = cellstr(dec2bin(pop_pheno(:, it), 5)); % need at least 5 bits force for maximum integer; Note: Genotype evolution can give back invalid individuals 57 | % calculate corresponding power loss 58 | power_loss(it) = calculation_119(pop_pheno(:,it)); 59 | end 60 | 61 | % Statistics administration 62 | evalcount = evalcount + 1; 63 | fopt = min(power_loss); 64 | histf(evalcount) = fopt; 65 | 66 | % Evolution loop 67 | while evalcount < evalbudget 68 | % Remember the best score for elitist step 69 | [~, eliteindex] = min(power_loss); 70 | elitePheno = pop_pheno(:,eliteindex); 71 | eliteGeno = pop_geno(:,eliteindex); 72 | elitePower = power_loss(eliteindex); 73 | 74 | %% Generate new population (crossover, mutation) 75 | for itPop = 1:mu 76 | % Tournament selection step 77 | competitors = randperm(mu, k_tourney); % pick k_tourney different individuals 78 | [~, sorted] = sort(power_loss); % Sort them on power_loss 79 | competitors_sorted = intersect(sorted, competitors, 'stable'); 80 | 81 | % find winner of tournament 82 | winner = competitors_sorted(1); % Default to fittest if nothing else found 83 | for itWin = 1:length(competitors_sorted) 84 | if (rand < pt*((1-pt)^(itWin-1))) 85 | winner = competitors_sorted(itWin); 86 | break 87 | end 88 | end 89 | 90 | % Select the first parent from pop_geno 91 | p1 = pop_geno(:,winner); 92 | 93 | % Crossover step 94 | if (rand() < pc) 95 | % Second tournament selection step to find second parent for 96 | % crossover 97 | competitors = randperm(mu, k_tourney); % pick k_tourney different chromosomes 98 | [~, sorted] = sort(power_loss); % Sort them on power_loss 99 | competitors_sorted = intersect(sorted, competitors, 'stable'); 100 | % throw away the foregoing winner however exact duplicates are 101 | % allowed 102 | competitors_sorted = competitors_sorted(competitors_sorted~=winner); 103 | 104 | % find winner of tournament chromosome 105 | winner = competitors_sorted(1); % Default to highest if nothing else found 106 | for itWin = 1:length(competitors_sorted) 107 | if (rand < pt*((1-pt)^(itWin-1))) 108 | winner = competitors_sorted(itWin); 109 | break 110 | end 111 | end 112 | p2 = pop_geno(:,winner);% Select the second parent from pop_geno 113 | 114 | % n point crossover at random points 115 | cross_point = sort(randperm(pheno_len, npoint)); 116 | % take into account last and first element for for loop 117 | cross_point = [1, cross_point, pheno_len]; 118 | % initialize variables 119 | child = cell(pheno_len, 1); % num2cell for bit strings 120 | usep1 = true; 121 | % do crossover 122 | for position = 1:(length(cross_point)-1) 123 | if usep1 == true 124 | child(cross_point(position):cross_point(position+1)) =... 125 | p1(cross_point(position):cross_point(position+1)); 126 | elseif usep1 == false 127 | child(cross_point(position):cross_point(position+1)) =... 128 | p2(cross_point(position):cross_point(position+1)); 129 | end 130 | usep1 = not(usep1); % use p1 and p2 alternately 131 | end 132 | % New individual is the crossover child 133 | Pnew_geno(:, itPop) = child; 134 | else 135 | Pnew_geno(:, itPop) = p1; % No crossover, copy the selected parent 136 | end % crossover for loop 137 | 138 | % Mutation step 139 | Pbinary = cell2mat(Pnew_geno(:, itPop)); 140 | for itGeno = 1:pheno_len 141 | for itBit = 1:size(Pbinary, 2) 142 | % Probability to mutate 143 | if (rand() < pm) 144 | % for comparison if 1 or 0 change from char to integer 145 | valueBit = str2num(Pbinary(itGeno, itBit)); 146 | if valueBit == 1 147 | Pbinary(itGeno, itBit) = num2str(0); 148 | elseif valueBit == 0 149 | Pbinary(itGeno, itBit) = num2str(1); 150 | end 151 | end 152 | end 153 | end 154 | % convert it back to a cell array 155 | Pnew_geno(:, itPop) = cellstr(Pbinary); 156 | Pnew_pheno(:, itPop) = bin2dec(Pbinary); 157 | 158 | % For the new phenotype population repair if integer value larger 159 | % than corresponding upperbound (ub) with random integer, update pheno and geno! 160 | for itPheno = 1:pheno_len 161 | if Pnew_pheno(itPheno, itPop) > ub(itPheno) 162 | Pnew_pheno(itPheno, itPop) = randi(ub(itPheno)); 163 | Pnew_geno(itPheno, itPop) = cellstr(dec2bin(Pnew_pheno(itPheno, itPop), 5)); 164 | end 165 | end 166 | end % end for loop crossover and mutation 167 | 168 | %% evaluate, apply elitism and overwrite with new population 169 | % Elitism step to keep the best generation 170 | for itPop = 1:mu 171 | % Evaluate if valid and overwrite old population value 172 | % otherwise if not valid keep old population individuals 173 | % after wards calculate power loss of individual 174 | if valid_119(Pnew_pheno(:,itPop)) == 1 175 | power_loss(itPop) = calculation_119(Pnew_pheno(:,itPop)); 176 | pop_pheno(:,itPop) = Pnew_pheno(:,itPop); 177 | pop_geno(:,itPop) = Pnew_geno(:,itPop); 178 | end 179 | end 180 | 181 | 182 | % applying elitisme, overwrite highest power loss individual 183 | [~, pos] = max(power_loss); 184 | pop_pheno(:,pos) = elitePheno; 185 | pop_geno(:,pos) = eliteGeno; 186 | power_loss(pos) = elitePower; 187 | 188 | % Statistics administration 189 | [fopt, optindex] = min(power_loss); 190 | 191 | aopt = pop_pheno(:,optindex); 192 | for itPop = 1:mu 193 | evalcount = evalcount + 1; 194 | histf(evalcount) = fopt; 195 | end 196 | end 197 | end -------------------------------------------------------------------------------- /mc.m: -------------------------------------------------------------------------------- 1 | function [aopt, fopt] = mc(evalbudget) 2 | % Set upperbounds, taken over from valid_119.m 3 | ub = [25;17;15;21;18;12;11;16;12;17;20;18;12;16;20]; 4 | 5 | % Load variables of the experiments 6 | load('para119.mat') 7 | 8 | % Add path of matpower4.1 9 | addpath('matpower4.1') 10 | 11 | % Statistics administration 12 | evalcount = 0; 13 | histf = zeros(1, evalbudget); 14 | 15 | % Initialize 16 | max_len = size(ub, 1); 17 | configuration = zeros(max_len, 1); 18 | 19 | % generate random solution and evalute 20 | while valid_119(configuration) == 0 21 | for it = 1:max_len 22 | configuration(it) = randi(ub(it), 1); 23 | end 24 | end 25 | fopt = calculation_119(configuration); 26 | aopt = configuration; 27 | 28 | % Statistics administration 29 | evalcount = evalcount + 1; 30 | histf(evalcount) = fopt; 31 | 32 | % Loop 33 | while evalcount < evalbudget 34 | % Generate random configuration and evaluate 35 | configurationRand = zeros(max_len, 1); 36 | for itInd = 1:max_len 37 | configurationRand(itInd) = randi(ub(itInd), 1); 38 | end 39 | 40 | 41 | if valid_119(configurationRand) 42 | power_loss = calculation_119(configurationRand); 43 | else 44 | % if not valid remain with same fopt and save it 45 | evalcount = evalcount + 1; 46 | histf(evalcount) = fopt; 47 | continue 48 | end 49 | 50 | % if new power loss value is lower then lowest power loss calculated 51 | % replace with new value and record corresponding vector 52 | if (power_loss < fopt) 53 | aopt = configurationRand; 54 | fopt = power_loss; 55 | end 56 | 57 | % Statistics administration 58 | evalcount = evalcount + 1; 59 | histf(evalcount) = fopt; 60 | end 61 | end -------------------------------------------------------------------------------- /para119.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sirvincent/ga_network_reconfiguration/f720d6d14906743df16d4221ed26666c4c019f19/para119.mat -------------------------------------------------------------------------------- /performance.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sirvincent/ga_network_reconfiguration/f720d6d14906743df16d4221ed26666c4c019f19/performance.png -------------------------------------------------------------------------------- /valid_119.m: -------------------------------------------------------------------------------- 1 | %% This function is to verify the structure of the chorm is valid or not 2 | % Input: 3 | % - chorm: 4 | % - mpc.branch: the data after deleting all the information of switches 5 | % Output: 6 | % - flag: 0 means not valid, 1 means valid 7 | % 8 | % This function is only available for 119 nodes test system 9 | 10 | % Kaifeng Yang, Feb. 20, 2014 11 | function flag = valid_119(chorm) 12 | further_test = 1; 13 | further_test_2 = 0; 14 | ub = [25;17;15;21;18;12;11;16;12;17;20;18;12;16;20]; 15 | for i=1:15 16 | if chorm(i,1) > ub(i,1) 17 | flag = 0; 18 | further_test = 0; 19 | end 20 | if chorm(i,1) < 1 21 | flag = 0; 22 | further_test = 0; 23 | end 24 | end 25 | 26 | 27 | if further_test == 1 28 | branch_data =[ 29 | 1 2 0.0002975 0.0001074 0 100 100 100 0 0 1 -360 360 30 | 2 3 0.0002727 0.0000983 0 100 100 100 0 0 1 -360 360 31 | 2 4 0.0003719 0.0001339 0 100 100 100 0 0 1 -360 360 32 | 4 5 0.0001240 0.0004463 0 100 100 100 0 0 1 -360 360 33 | 5 6 0.0001240 0.0004463 0 100 100 100 0 0 1 -360 360 34 | 6 7 0.0001240 0.0001033 0 100 100 100 0 0 1 -360 360 35 | 7 8 0.0001488 0.0001157 0 100 100 100 0 0 1 -360 360 36 | 8 9 0.0001736 0.0005207 0 100 100 100 0 0 1 -360 360 37 | 2 10 0.0013719 0.0011107 0 100 100 100 0 0 1 -360 360 38 | 10 11 0.0009256 0.0006521 0 100 100 100 0 0 1 -360 360 39 | 11 12 0.0015455 0.0025868 0 100 100 100 0 0 1 -360 360 40 | 12 13 0.0011736 0.0012496 0 100 100 100 0 0 1 -360 360 41 | 13 14 0.0014876 0.0009752 0 100 100 100 0 0 1 -360 360 42 | 14 15 0.0012397 0.0003719 0 100 100 100 0 0 1 -360 360 43 | 15 16 0.0013223 0.0014876 0 100 100 100 0 0 1 -360 360 44 | 16 17 0.0012975 0.0014132 0 100 100 100 0 0 1 -360 360 45 | 11 18 0.0018017 0.0023554 0 100 100 100 0 0 1 -360 360 46 | 18 19 0.0009752 0.0015289 0 100 100 100 0 0 1 -360 360 47 | 19 20 0.0013223 0.0016198 0 100 100 100 0 0 1 -360 360 48 | 20 21 0.0009917 0.0015620 0 100 100 100 0 0 1 -360 360 49 | 21 22 0.0009917 0.0006521 0 100 100 100 0 0 1 -360 360 50 | 22 23 0.0116529 0.0059752 0 100 100 100 0 0 1 -360 360 51 | 23 24 0.0024215 0.0011140 0 100 100 100 0 0 1 -360 360 52 | 24 25 0.0010992 0.0008595 0 100 100 100 0 0 1 -360 360 53 | 25 26 0.0014711 0.0011074 0 100 100 100 0 0 1 -360 360 54 | 26 27 0.0014711 0.0011074 0 100 100 100 0 0 1 -360 360 55 | 4 28 0.0001240 0.0002446 0 100 100 100 0 0 1 -360 360 56 | 28 29 0.0000992 0.0002281 0 100 100 100 0 0 1 -360 360 57 | 29 30 0.0009917 0.0022860 0 100 100 100 0 0 1 -360 360 58 | 30 31 0.0017355 0.0020083 0 100 100 100 0 0 1 -360 360 59 | 31 32 0.0009917 0.0004463 0 100 100 100 0 0 1 -360 360 60 | 32 33 0.0014711 0.0019339 0 100 100 100 0 0 1 -360 360 61 | 33 34 0.0014711 0.0019339 0 100 100 100 0 0 1 -360 360 62 | 34 35 0.0012727 0.0013388 0 100 100 100 0 0 1 -360 360 63 | 30 36 0.0015455 0.0021570 0 100 100 100 0 0 1 -360 360 64 | 36 37 0.0010992 0.0008182 0 100 100 100 0 0 1 -360 360 65 | 29 38 0.0027273 0.0016033 0 100 100 100 0 0 1 -360 360 66 | 38 39 0.0025620 0.0016033 0 100 100 100 0 0 1 -360 360 67 | 39 40 0.0010744 0.0016033 0 100 100 100 0 0 1 -360 360 68 | 40 41 0.0023140 0.0012397 0 100 100 100 0 0 1 -360 360 69 | 41 42 0.0097521 0.0070248 0 100 100 100 0 0 1 -360 360 70 | 42 43 0.0034711 0.0020132 0 100 100 100 0 0 1 -360 360 71 | 43 44 0.0022314 0.0008033 0 100 100 100 0 0 1 -360 360 72 | 44 45 0.0028017 0.0010091 0 100 100 100 0 0 1 -360 360 73 | 45 46 0.0022314 0.0014702 0 100 100 100 0 0 1 -360 360 74 | 35 47 0.0017355 0.0011430 0 100 100 100 0 0 1 -360 360 75 | 47 48 0.0009917 0.0006521 0 100 100 100 0 0 1 -360 360 76 | 48 49 0.0012397 0.0008157 0 100 100 100 0 0 1 -360 360 77 | 49 50 0.0012397 0.0008157 0 100 100 100 0 0 1 -360 360 78 | 50 51 0.0019835 0.0013066 0 100 100 100 0 0 1 -360 360 79 | 51 52 0.0009917 0.0006521 0 100 100 100 0 0 1 -360 360 80 | 52 53 0.0033471 0.0012050 0 100 100 100 0 0 1 -360 360 81 | 53 54 0.0033471 0.0012050 0 100 100 100 0 0 1 -360 360 82 | 29 55 0.0032314 0.0011653 0 100 100 100 0 0 1 -360 360 83 | 55 56 0.0033554 0.0012074 0 100 100 100 0 0 1 -360 360 84 | 56 57 0.0033554 0.0012074 0 100 100 100 0 0 1 -360 360 85 | 57 58 0.0058347 0.0045132 0 100 100 100 0 0 1 -360 360 86 | 58 59 0.0027934 0.0010066 0 100 100 100 0 0 1 -360 360 87 | 59 60 0.0027934 0.0010066 0 100 100 100 0 0 1 -360 360 88 | 60 61 0.0017107 0.0006174 0 100 100 100 0 0 1 -360 360 89 | 61 62 0.0020413 0.0073736 0 100 100 100 0 0 1 -360 360 90 | 1 63 0.0002314 0.0003455 0 100 100 100 0 0 1 -360 360 91 | 63 64 0.0009669 0.0016661 0 100 100 100 0 0 1 -360 360 92 | 64 65 0.0021074 0.0007587 0 100 100 100 0 0 1 -360 360 93 | 65 66 0.0017355 0.0006273 0 100 100 100 0 0 1 -360 360 94 | 66 67 0.0031653 0.0011405 0 100 100 100 0 0 1 -360 360 95 | 67 68 0.0041653 0.0027298 0 100 100 100 0 0 1 -360 360 96 | 68 69 0.0033554 0.0012074 0 100 100 100 0 0 1 -360 360 97 | 69 70 0.0079504 0.0062893 0 100 100 100 0 0 1 -360 360 98 | 70 71 0.0013636 0.0004959 0 100 100 100 0 0 1 -360 360 99 | 71 72 0.0025041 0.0009025 0 100 100 100 0 0 1 -360 360 100 | 72 73 0.0025041 0.0009025 0 100 100 100 0 0 1 -360 360 101 | 73 74 0.0017025 0.0011901 0 100 100 100 0 0 1 -360 360 102 | 74 75 0.0019256 0.0006942 0 100 100 100 0 0 1 -360 360 103 | 75 76 0.0048843 0.0014653 0 100 100 100 0 0 1 -360 360 104 | 76 77 0.0010413 0.0003744 0 100 100 100 0 0 1 -360 360 105 | 64 78 0.0046198 0.0030471 0 100 100 100 0 0 1 -360 360 106 | 78 79 0.0015372 0.0010140 0 100 100 100 0 0 1 -360 360 107 | 79 80 0.0015372 0.0010140 0 100 100 100 0 0 1 -360 360 108 | 80 81 0.0021488 0.0011488 0 100 100 100 0 0 1 -360 360 109 | 81 82 0.0012727 0.0012231 0 100 100 100 0 0 1 -360 360 110 | 82 83 0.0019008 0.0010579 0 100 100 100 0 0 1 -360 360 111 | 83 84 0.0020826 0.0008760 0 100 100 100 0 0 1 -360 360 112 | 84 85 0.0014876 0.0012231 0 100 100 100 0 0 1 -360 360 113 | 79 86 0.0013223 0.0015041 0 100 100 100 0 0 1 -360 360 114 | 86 87 0.0016529 0.0019008 0 100 100 100 0 0 1 -360 360 115 | 87 88 0.0013223 0.0032479 0 100 100 100 0 0 1 -360 360 116 | 65 89 0.0055289 0.0019934 0 100 100 100 0 0 1 -360 360 117 | 89 90 0.0021983 0.0010140 0 100 100 100 0 0 1 -360 360 118 | 90 91 0.0021983 0.0010140 0 100 100 100 0 0 1 -360 360 119 | 91 92 0.0021983 0.0010140 0 100 100 100 0 0 1 -360 360 120 | 92 93 0.0021983 0.0010140 0 100 100 100 0 0 1 -360 360 121 | 93 94 0.0019256 0.0009504 0 100 100 100 0 0 1 -360 360 122 | 94 95 0.0040992 0.0011405 0 100 100 100 0 0 1 -360 360 123 | 91 96 0.0016198 0.0014876 0 100 100 100 0 0 1 -360 360 124 | 96 97 0.0016198 0.0014876 0 100 100 100 0 0 1 -360 360 125 | 97 98 0.0015421 0.0010083 0 100 100 100 0 0 1 -360 360 126 | 98 99 0.0006165 0.0026281 0 100 100 100 0 0 1 -360 360 127 | 1 100 0.0005165 0.0002190 0 100 100 100 0 0 1 -360 360 128 | 100 101 0.0012405 0.0019339 0 100 100 100 0 0 1 -360 360 129 | 101 102 0.0011132 0.0007339 0 100 100 100 0 0 1 -360 360 130 | 102 103 0.0019066 0.0009942 0 100 100 100 0 0 1 -360 360 131 | 103 104 0.0036942 0.0013289 0 100 100 100 0 0 1 -360 360 132 | 104 105 0.0013488 0.0004860 0 100 100 100 0 0 1 -360 360 133 | 105 106 0.0027273 0.0008182 0 100 100 100 0 0 1 -360 360 134 | 106 107 0.0012893 0.0004636 0 100 100 100 0 0 1 -360 360 135 | 107 108 0.0031562 0.0011355 0 100 100 100 0 0 1 -360 360 136 | 108 109 0.0013438 0.0004835 0 100 100 100 0 0 1 -360 360 137 | 109 110 0.0031562 0.0011355 0 100 100 100 0 0 1 -360 360 138 | 110 111 0.0020207 0.0007264 0 100 100 100 0 0 1 -360 360 139 | 110 112 0.0017256 0.0006223 0 100 100 100 0 0 1 -360 360 140 | 112 113 0.0019017 0.0006843 0 100 100 100 0 0 1 -360 360 141 | 100 114 0.0050430 0.0018149 0 100 100 100 0 0 1 -360 360 142 | 114 115 0.0015421 0.0010496 0 100 100 100 0 0 1 -360 360 143 | 115 116 0.0030843 0.0020331 0 100 100 100 0 0 1 -360 360 144 | 116 117 0.0033471 0.0030331 0 100 100 100 0 0 1 -360 360 145 | 117 118 0.0040413 0.0036198 0 100 100 100 0 0 1 -360 360 146 | 147 | 46 27 0.0043455 0.0024174 0 100 100 100 0 0 1 -360 360 148 | 17 27 0.0043455 0.0024099 0 100 100 100 0 0 1 -360 360 149 | 8 24 0.0035306 0.0012719 0 100 100 100 0 0 1 -360 360 150 | 54 43 0.0039669 0.0014281 0 100 100 100 0 0 1 -360 360 151 | 62 49 0.0029752 0.0010711 0 100 100 100 0 0 1 -360 360 152 | 37 62 0.0047107 0.0047273 0 100 100 100 0 0 1 -360 360 153 | 9 40 0.0043802 0.0027669 0 100 100 100 0 0 1 -360 360 154 | 58 96 0.0032702 0.0011777 0 100 100 100 0 0 1 -360 360 155 | 73 91 0.0056198 0.0053554 0 100 100 100 0 0 1 -360 360 156 | 88 75 0.0033570 0.0012099 0 100 100 100 0 0 1 -360 360 157 | 99 77 0.0038231 0.0013835 0 100 100 100 0 0 1 -360 360 158 | 108 83 0.0053802 0.0019339 0 100 100 100 0 0 1 -360 360 159 | 105 86 0.0067149 0.0024174 0 100 100 100 0 0 1 -360 360 160 | 110 118 0.0058587 0.0021099 0 100 100 100 0 0 1 -360 360 161 | 25 35 0.0041322 0.0041322 0 100 100 100 0 0 1 -360 360 162 | ]; 163 | code = [ 164 | 27 26 25 24 23 22 21 20 19 18 11 10 4 28 29 38 39 40 41 42 43 44 45 46 119 165 | 17 16 15 14 13 12 18 19 20 21 22 23 24 25 26 27 120 0 0 0 0 0 0 0 0 166 | 24 23 22 21 20 19 18 11 10 4 5 6 7 8 121 0 0 0 0 0 0 0 0 0 0 167 | 43 42 41 40 39 38 30 31 32 33 34 35 47 48 49 50 51 52 53 54 122 0 0 0 0 168 | 49 48 47 35 34 33 32 31 30 55 56 57 58 59 60 61 62 123 0 0 0 0 0 0 0 169 | 170 | 37 36 30 55 56 57 58 59 60 61 62 124 0 0 0 0 0 0 0 0 0 0 0 0 0 171 | 9 8 7 6 5 28 29 38 39 40 125 0 0 0 0 0 0 0 0 0 0 0 0 0 0 172 | 58 57 56 55 29 28 4 2 63 64 65 89 90 91 96 126 0 0 0 0 0 0 0 0 0 173 | 91 90 89 66 67 68 69 70 71 72 73 127 0 0 0 0 0 0 0 0 0 0 0 0 0 174 | 75 74 73 72 71 70 69 68 67 66 65 78 79 86 87 88 128 0 0 0 0 0 0 0 0 175 | 176 | 99 98 97 96 91 90 89 66 67 68 69 70 71 72 73 74 75 76 77 129 0 0 0 0 0 177 | 83 82 81 80 79 78 64 63 100 101 102 103 104 105 106 107 108 130 0 0 0 0 0 0 0 178 | 86 79 78 64 63 100 101 102 103 104 105 131 0 0 0 0 0 0 0 0 0 0 0 0 0 179 | 110 109 108 107 106 105 104 103 102 101 114 115 116 117 118 132 0 0 0 0 0 0 0 0 0 180 | 25 24 23 22 21 20 19 18 11 10 4 28 29 30 31 32 33 34 35 133 0 0 0 0 0 181 | ]; 182 | delete_branch = zeros(15,1); 183 | for i = 1:15 184 | delete_branch(i,1) = code(i,chorm(i)); 185 | end 186 | 187 | branch_data(delete_branch-1,:)=[]; 188 | 189 | 190 | % no_delete_same_point = 0; 191 | % [m_branch_first_test,n_branch_first_test] = size(branch_data); 192 | % if m_branch_first_test > 117 193 | % no_delete_same_point = 1; 194 | % flag = 0; 195 | % end 196 | % 197 | % if no_delete_same_point == 0 198 | 199 | 200 | 201 | 202 | [m_branch_data, n_branch_data] = size(branch_data); 203 | if m_branch_data >117 204 | flag = 0; 205 | else 206 | further_test_2 = 1; 207 | end 208 | 209 | if further_test_2 ==1 210 | node_searched = zeros(118,2); 211 | for i = 1:118 212 | node_searched(i,1) = i; 213 | end 214 | node_searched(1,2) = 1; 215 | 216 | 217 | % Find the original source, node No. 1 218 | num_row_1 = find(branch_data(:,1)==1); 219 | [m_1,n_1] = size(num_row_1); 220 | % node_next 221 | % The next nodes information of the current line segment, this number is a matrix 222 | node_next = ones(m_1,n_1); 223 | for i = 1:m_1 224 | node_next(i,1) = branch_data(num_row_1(i,1), 2); 225 | node_searched(node_next(i,1),2) = 1; 226 | end 227 | 228 | % Delete the processed data(The line segment of first node is No. 1 ) 229 | branch_data(num_row_1,:) = []; 230 | % Size the matrix of the branch 231 | [m_branch,n_branch] = size(branch_data); 232 | 233 | 234 | 235 | 236 | clear m_1; 237 | clear n_1; 238 | flag =1; 239 | 240 | % Loop when all the data is not complete 241 | % When find a loop or a isolate island, set m_branch = 0 and flag = 0; 242 | while (m_branch ~=0) 243 | current_node = node_next; 244 | clear node_next; 245 | [m_c, n_v] = size(current_node); 246 | if m_c == 0 247 | m_branch = 0; 248 | break; 249 | end 250 | % Find in the first line 251 | num_row_next = find(branch_data(:,1)==current_node(1,1)); 252 | for i = 2:m_c 253 | num_row_next = [num_row_next;find(branch_data(:,1)==current_node(i,1))]; 254 | end 255 | 256 | [m_n1,n_n1] = size(num_row_next); 257 | node_next = ones(m_n1,n_n1); 258 | for i =1:m_n1 259 | node_next(i,1) = branch_data(num_row_next(i,1),2); 260 | node_searched(node_next(i,1),2) = 1; 261 | end 262 | 263 | 264 | 265 | % Find in the second line 266 | for i = 1:m_c 267 | num_row_next = [num_row_next;find(branch_data(:,2)==current_node(i,1))]; 268 | end 269 | 270 | [m_n2,n_n2] = size(num_row_next); 271 | 272 | for i =(1+m_n1):m_n2 273 | node_next(i,1) = branch_data(num_row_next(i,1),1); 274 | node_searched(node_next(i,1),2) = 1; 275 | end 276 | % Delete all the current information 277 | branch_data(num_row_next,:) = []; 278 | clear current_node; 279 | clear num_row_next; 280 | % Calculate the size of the branch 281 | [m_branch,n_branch] = size(branch_data); 282 | 283 | end 284 | 285 | 286 | flag = all(node_searched(:,2)==1); 287 | 288 | 289 | end 290 | end 291 | end 292 | 293 | 294 | 295 | 296 | 297 | 298 | --------------------------------------------------------------------------------