Tell me efficient way
In hardware topology , each cell will have x1 number of input lines ( called as fan-in ) and y1 number of output lines ( called as fan-out ).the requirement is to identify the nearest cell with maximum fan-out.The input given is X Y coordinate of new cell. Then we want to find nearest one from the csv file. then wants to produce it fan-out?
For the problem definition , cell is defined by x-y co-ordinates.take a csv file as input.
The code given above is working correctly but i want to know is there is any other efficint way to do it?
public static void main(String args) throws Exception
FileInputStream fin = new FileInputStream("empty");
DataInputStream in=new DataInputStream(fin);
BufferedReader br=new BufferedReader(new InputStreamReader(in));
double y=new double;
double dist=new double;
double copy=new double;
double fanout=new double;
Scanner user=new Scanner(System.in);
System.out.println("Enter x value::\n");
System.out.println("\nEnter y value::\n");
System.out.println("\n\n*******Content of CSV file**********\n\n");
while ((strline=br.readLine())!= null)
System.out.println("Number format exception for input string");
System.out.println("\n \nfan-out= "+fanout[i]);
When posting code, use the code tags. Put [code] at the start of your code and [/code] at the end: that way the code will be properly formatted when it appears in the forum.
What does "efficient" mean? In particular if it includes maintainability of the code, consider
* many small methods rather than a long deeply nested main(). Document what each method does.
* use descriptive variables. The extra key strokes make for self documenting code.
* define and use classes. A cell (with id, location and fan characteristics) looks like an ideal candidate for being modelled by a Cell class. A network of cells might be another class with the important behaviour of reporting the closest cell to a given location.
As far as finding the closest element of a point set to a given location is concerned, there are better ways than brute forcing your way through the set. But get the code clean first as efficiency in this narrow sense requires storing the collection of cells in a more sorted order than merely an array indexed by their position in the data file.
I don't know, because the OPs requirement is:
Originally Posted by pbrockway2
If I read it correctly the requirement is either: find the cell with the maximum fan-out or (this is another interpretation), in case more than one cell are 'nearest' to the current cell, select the cell with the maximum fan-out from that subset of cells. If the first interpretation is correct all cells need to be checked; if the second interpretation is correct, the problem reduces to finding the nearest cell(s); this can be done by checking all cells in an expanding circle with the current cell as the centre of the circle. Next a brute force needs to be applied over those nearest cell(s).