class ns{
public double rs;
public double rab;
public double[][] self;
public double[][] doubleArray = new double[250][2];
public double[] affity = new double[10];
public double[][] test;
public double[] dir;
public double[] dir2;
public double[][] dTest;
public int[][] dLabel;
public double[][] testSelf;
public int[][] selfLabel;
public void nsd(){
rs= 0.34;
rab= 0.35;
self = new double[10][2];
self[0][0] = 0.2265;
self[0][1] = 0.1423;
self[1][0] = 0.2871;
self[1][1] = 0.2186;
self[2][0] = 0.273;
self[2][1] = 0.1977;
self[3][0] = 0.265;
self[3][1] = 0.2008;
self[4][0] = 0.1426;
self[4][1] = 0.0567;
self[5][0] = 0.17;
self[5][1] = 0.0797;
self[6][0] = 0.1772;
self[6][1] = 0.087;
self[7][0] = 0.2773;
self[7][1] = 0.2113;
self[8][0] = 0.2874;
self[8][1] = 0.2288;
self[9][0] = 0.3045;
self[9][1] = 0.2572;
test = new double[14][2];
test[0][0] = 0.2265;
test[0][1] = 0.1423;
test[1][0] = 0.2871;
test[1][1] = 0.2186;
test[2][0] = 0.273;
test[2][1] = 0.1977;
test[3][0] = 0.265;
test[3][1] = 0.2008;
test[4][0] = 0.1426;
test[4][1] = 0.0567;
test[5][0] = 0.17;
test[5][1] = 0.0797;
test[6][0] = 0.1772;
test[6][1] = 0.087;
test[7][0] = 0.2773;
test[7][1] = 0.2113;
test[8][0] = 0.2874;
test[8][1] = 0.2288;
test[9][0] = 0.3045;
test[9][1] = 0.2572;
test[10][0] = 0.3245;
test[10][1] = 0.22;
test[11][0] = 0.2866;
test[11][1] = 0.2279;
test[12][0] = 0.2308;
test[12][1] = 0.1464;
test[13][0] = 0.2544;
test[13][1] = 0.18;
dir=new double[250];
dir2=new double[250];
dTest=new double[250][2];
dLabel=new int[250][2];
testSelf=new double[10][2];
selfLabel=new int[10][2];
}
public void geneRandom(int m,int n){
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
doubleArray[i][j] = Math.random();
}
}
}
public void geneDetector(){
for (int i = 0; i < 250; i++) {
for (int j = 0; j < 250; j++){
for(int n = 0; n < 10; n++){
affity[n]= Math.sqrt(Math.pow(doubleArray[j][0]-self[n][0], 2)+Math.pow(doubleArray[j][1]-self[n][1], 2));
if(affity[n]<=rab+rs){
doubleArray[j][0]=Math.random();
doubleArray[j][1]=Math.random();
}
else{
doubleArray[j][0]=doubleArray[j][0];
doubleArray[j][1]=doubleArray[j][1];
}
}
}
}
}
public void Test(){
double dTestmin;
double dir2min;
for(int i=0;i<14;i++){
for(int j=0;j<250;j++){
dir[j]=Math.sqrt(Math.pow(test[i][0]-doubleArray[j][0], 2)+Math.pow(test[i][1]-doubleArray[j][1], 2));
dTest[j][1]=dir[j];
dLabel[j][1]=j;
}
dTestmin = dTest[1][1];
for(int j=0;j<dTest.length;j++){
if(dTest[j][1]<dTestmin){
double temp = 0;
temp =dTestmin;
dTestmin = dTest[j][1];
dTest[j][1] = temp;
}
}
if(dTestmin<rab){
System.out.println("This data is detected!");
}
else{
for(int p=0;p<10;p++){
dir2[p]=Math.sqrt(Math.pow(test[i][0]-doubleArray[p][0], 2)+Math.pow(test[i][1]-doubleArray[p][1], 2));
testSelf[p][1]=dir2[p];
selfLabel[p][1]=p;
}
dir2min = testSelf[1][1];
for(int j=0;j<testSelf.length;j++){
if(testSelf[j][1]<dir2min){
double temp = 0;
temp =dir2min;
dir2min = testSelf[j][1];
testSelf[j][1] = temp;
}
}
if(dir2min<=rs){
System.out.println(test[i][0] +"This data is self data!");
}
else{
System.out.println(test[i][0] +"This data is not detected and not a self data!");
}
}
}
}
}
public class nsa{
public static void main(String[] args) {
System.out.println("Hello World!");
ns nsEx=new ns();
nsEx.nsd();
nsEx.geneRandom(250,2);
nsEx.geneDetector();
nsEx.Test();
}
}