clc; clear; close all; load('new_point'); round=1; death_nodes=[]; communication=[]; energy=[]; while round<=100 for i=1:1:node_number S(i).father=-1; S(i).child_num=0; S(i).intree=0; S(i).data=data_length; S(i).ifleaf=1; S(i).child_leaf=0; S(i).child_middle=0; S(i).child=[]; end sink.child=[]; sink.CHO=[]; sink.num_neighbor=0; for i=1:1:node_number dis=sqrt((sink.x-S(i).xd)^2+(sink.y-S(i).yd)^2); if dis0 for j=1:1:S(i).child_num if S(S(i).child(j)).ifleaf==1 S(i).child_leaf= S(i).child_leaf+1; else S(i).child_middle=S(i).child_middle+1; end end end end for i=1:1:node_number if S(i).ifleaf==1 S(i).PIOC=0; end end count=0; sink.num_child=0; for i=1:1:sink.num_neighbor if S(sink.child(i)).ifleaf==1 count=count+1; else sink.num_child=sink.num_child+1; end end over_flag_1=1; while 1 over_flag_1=1; for i=1:1:sink.num_neighbor if S(sink.child(i)).PIOC==0 list_head=sink.child(i); S(list_head).father=0; sink.num_child=sink.num_child+1; over_flag_1=0; break; end end if over_flag_1==1 break; end over_flag_2=1; while 1 S(list_head).PIOC=1; father=list_head; over_flag_2=1; for i=1:1:sink.num_neighbor if S(sink.child(i)).ifleaf==1&&S(sink.child(i)).PIOC==0 dis=sqrt((S(sink.child(i)).xd-S(list_head).xd)^2+ ... (S(sink.child(i)).yd-S(list_head).yd)^2); if disJ) j=1; rem_j(j)=randi(S(i).num_neighbor); while j