function result = allocate(a) Num = 9; sum = 0; bias_1 = 0.7; bias_2 = 1 - bias_1; x = []; y = []; for i = 1:Num x(i) = a(i*2-1); y(i) = a(i*2); end for i = 1:Num min = 9999; for j = 1:Num if i == j break end dis = sqrt(power((x(i)-x(j)), 2)+power((y(i)-y(j)), 2)); ifmin > dis min = dis; end end ifmin ~= 9999 sum = sum + min; end end mid = sum/Num; adjust = 0; for i = 1:Num min = 9999; for j = 1:Num if i == j break end dis = sqrt(power((x(i)-x(j)), 2)+power((y(i)-y(j)), 2)); ifmin > dis min = dis; end end ifmin ~= 9999 adjust = adjust + bias_2*abs(min - mid); end end sum*bias_1; adjust; result = -bias_1*sum + adjust; %x_1 = a(1); %y = a(2); end
方形可视化:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
function plots(a) Num = 9; x = []; y = []; for i = 1:Num x(i) = a(i*2-1); y(i) = a(i*2); end % plot(x(1),y(1), '*'); for i = 1:Num plot(x(i), y(i), '*'); [x(i),y(i)] hold on; end end
function result = allocate_circle(a) Num = 8; sum = 0; bias_1 = 0.7; bias_2 = 1 - bias_1; % x为r,y为theta x = []; y = []; for i = 1:Num x(i) = a(i*2-1); y(i) = a(i*2); end for i = 1:Num min = 9999; for j = 1:Num if i == j break end x_1 = x(i)*cos(y(i)); y_1 = x(i)*sin(y(i)); x_2 = x(j)*cos(y(j)); y_2 = x(j)*sin(y(j)); % dis = sqrt(power((x(i)-x(j)), 2)+power((y(i)-y(j)), 2)); dis = sqrt(power(x_1-x_2, 2)+power(y_1-y_2, 2)); ifmin > dis min = dis; end end ifmin ~= 9999 sum = sum + min; end end mid = sum/Num; adjust = 0; for i = 1:Num min = 9999; for j = 1:Num if i == j break end x_1 = x(i)*cos(y(i)); y_1 = x(i)*sin(y(i)); x_2 = x(j)*cos(y(j)); y_2 = x(j)*sin(y(j)); % dis = sqrt(power((x(i)-x(j)), 2)+power((y(i)-y(j)), 2)); dis = sqrt(power(x_1-x_2, 2)+power(y_1-y_2, 2)); ifmin > dis min = dis; end end ifmin ~= 9999 adjust = adjust + bias_2*abs(min - mid); end end sum*bias_1; adjust; result = -bias_1*sum + adjust; %x_1 = a(1); %y = a(2); end
function plots_circle(a) Num = 8; x = []; y = []; for i = 1:Num x(i) = a(i*2-1); y(i) = a(i*2); end % plot(x(1),y(1), '*'); for i = 1:Num plot(x(i)*cos(y(i)), x(i)*sin(y(i)), '*'); [x(i),y(i)] hold on; end theta=0:2*pi/3600:2*pi; r = 1;
function result = allocate_qiu(a) Num = 6; sum = 0; bias_1 = 0.7; bias_2 = 1 - bias_1; % x为r,y为theta,z为phi x = []; y = []; z = []; for i = 1:Num x(i) = a(i*3-2); y(i) = a(i*3-1); z(i) = a(i*3); end for i = 1:Num min = 9999; for j = 1:Num if i == j break end x_1 = x(i)*cos(z(i))*cos(y(i)); y_1 = x(i)*cos(z(i))*sin(y(i)); z_1 = x(i)*sin(z(i)); x_2 = x(j)*cos(z(j))*cos(y(j)); y_2 = x(j)*cos(z(j))*sin(y(j)); z_2 = x(j)*sin(z(j)); % dis = sqrt(power((x(i)-x(j)), 2)+power((y(i)-y(j)), 2)); % dis = sqrt(power(x_1-x_2, 2)+power(y_1-y_2, 2)); dis = power(power(x_1-x_2,2)+power(y_1-y_2,2)+power(z_1-z_2,2),1/3); ifmin > dis min = dis; end end ifmin ~= 9999 sum = sum + min; end end mid = sum/Num; adjust = 0; for i = 1:Num min = 9999; for j = 1:Num if i == j break end x_1 = x(i)*cos(z(i))*cos(y(i)); y_1 = x(i)*cos(z(i))*sin(y(i)); z_1 = x(i)*sin(z(i)); x_2 = x(j)*cos(z(j))*cos(y(j)); y_2 = x(j)*cos(z(j))*sin(y(j)); z_2 = x(j)*sin(z(j)); % dis = sqrt(power((x(i)-x(j)), 2)+power((y(i)-y(j)), 2)); % dis = sqrt(power(x_1-x_2, 2)+power(y_1-y_2, 2)); dis = power(power(x_1-x_2,2)+power(y_1-y_2,2)+power(z_1-z_2,2),1/3); ifmin > dis min = dis; end end ifmin ~= 9999 adjust = adjust + bias_2*abs(min - mid); end end sum*bias_1; adjust; result = -bias_1*sum + adjust; %x_1 = a(1); %y = a(2); end
球可视化
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
function plots_qiu(a) Num = 6; x = []; y = []; z = []; for i = 1:Num x(i) = a(i*3-2); y(i) = a(i*3-1); z(i) = a(i*3); end % plot(x(1),y(1), '*'); for i = 1:Num % plot(x(i)*cos(z(i))*cos(y(i)), x(i)*cos(z(i))*sin(y(i)), '*'); scatter3(x(i)*cos(z(i))*cos(y(i)),x(i)*cos(z(i))*sin(y(i)),x(i)*sin(z(i)),'k'); [x(i)*cos(z(i))*cos(y(i)),x(i)*cos(z(i))*sin(y(i))]; hold on; end end