package battery.utility;


import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;

public class Points {
	
	public static int MAX_LENGHT = 1000;
	
	public static int[] x = new int [MAX_LENGHT];
	public static int[] y = new int [MAX_LENGHT];
	public static int row;
	public static int col;
	public static int[] S = new int [MAX_LENGHT];
	public static int[] P = new int [MAX_LENGHT];
	public static int S_length;
	public static double[] Emission = new double [MAX_LENGHT];
	

	public static void Prim() {
		S[0]= 0;
		P[0]= 0;
		for (S_length=1; S_length<row;S_length++){
			// Extract minimum distance to node S_Lenght 
			double min = ExtractMin();	
		}		
		ExtraxtEmission();
	}
	
	public static double ExtractMin() {
		double min=1000000; 
		for (int s=0; s<S_length;s++){
			for (int v=0; v<row;v++){
				if (notInS(v) && (distance(S[s],v)<min)) {
					min = distance(S[s],v);
					S[S_length]=v;
					P[S_length]=S[s];
				}
			}
			
		}
		return min;
	}
	
	public static void ExtraxtEmission() {
		for (int s=0; s<row;s++){
			Emission[S[s]]= distance(S[s],P[s]);
		}
		for (int s=0; s<row;s++){
			for (int j=0; j<row;j++){
				if (P[j]==S[s]){
					double d =distance(S[s],S[j]);				
					if ( Emission[S[s]] < d ){
						Emission[S[s]] = d;
					}
				}
			}
		}
		for (int s=0; s<row;s++){
			System.out.println("Sensor" + s + "  Emission distance: " + Emission[s]);
		}
	}
		
	public static boolean notInS(int node) {
		for (int i=0; i<S_length;i++){
			if (S[i]==node) return false;
		}
		return true;
	}
	
	public static double distance(int i, int j) {
		double d = Math.sqrt( (x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]) );
		return d;
	}	
	
	
}
