package uk.ac.leeds.ccg.cluster; // tst class for grid search in GAM/K // // J R Davy // Jan 1998 import java.io.*; import java.awt.*; import java.util.*; //import com.sun.java.util.collections.*; //change for 1.2! import uk.ac.leeds.ccg.geotools.*; import uk.ac.leeds.ccg.geotools.misc.*; import uk.ac.leeds.ccg.widgets.*; public class GamSearch implements Constants{ Label rx; Vector circles=new Vector(); //Vector visits=new Vector(); Vector scores= new Vector(); Shader sh=null; Results results; MyCircleLayer cl=null; private double radMax, // Maximum circle radius radMin, // Minimum circle radius radInc, // Circle increment xMinE, // Minimum easting xMaxE, // Maximum easting xMinN, // Minimum northing xMaxN, // Maximum northing rangeN, // Northing range rangeE, // Easting range overlp; // Circle overlap private int minE, // Minimum easting maxE, // Maximum easting minN, // Minimum northing maxN, // Maximum northing minPnt ,// Minimum point count totCal, totDat, totNHy, totNC2; int id =1; Database db; SignificanceTest tst; GamParameters pars; GeoRectangle bounds; public Results getResults(){ return results; } public GamSearch(Database db, GamParameters pars){ this.db=db; this.pars=pars; // Get parameters from Parameters class radMin = pars.getRadMin(); radMax = pars.getRadMax(); radInc = pars.getRadInc(); minPnt = pars.getMinPointCount(); overlp = pars.getOverlp(); // Find max and min x, y values to define search region bounds=db.getBounds(); xMinE = bounds.x; xMinN = bounds.y; xMaxE = bounds.x+bounds.width; xMaxN = bounds.y+bounds.height; System.out.print("\n*Minimum easting is " + xMinE); System.out.println(" Maximum is " + xMaxE); System.out.print("*Minimum northing is " + xMinN); System.out.println(" Maximum is " + xMaxN); // Establish spatial regions minN = (int) (xMinN - 1.0); minE = (int) (xMinE - 1.0); maxN = (int) (xMaxN + 1.0); maxE = (int) (xMaxE + 1.0); rangeN = maxN - minN; rangeE = maxE - minE; System.out.println("Northern range is " + rangeN + " East range is " + rangeE); // adjust region size for radius of max circle float nDiff = (float) (xMaxN + 2.0 * radMax + 1.0 - xMinN); float eDiff = (float)(xMaxE + 2.0 * radMax + 1.0 - xMinE); float range = Misc.max(nDiff, eDiff); // try for finest possible scaling given memory restrictions } int nCalc = 0,TotalCalc=0; public void sequentialSearch(Vector L, double radius, MyInt numCals, MyInt numHy, int sample,GeoRectangle rec){ int nDat, nCals, nHy; nDat = nCals = nHy = 0; double stat = (double) 0.0; double step = radius * overlp; double radSq = radius * radius; int nTimes = (int) (rec.getHeight()/step + (float) 1.0); double cX, cY = rec.y - step; GeoCircle gc = new GeoCircle(); int eTimes = (int) (rec.getWidth()/step + (float) 1.0); //System.out.println("Ntimes "+nTimes+" et "+eTimes); // Grid search: northern loop for (int iRow=0; iRow < nTimes; iRow++){ cY += step; cX = rec.getX() - step; //System.out.println("searching "+cX+" "+cY); // grid search: easting loop for (int iCol = 0; iCol < eTimes; iCol++){ cX += step; if(cl!=null&&!pars.getAnimate()) cl.setPos(cX,cY); gc.setCentre(cX,cY); gc.setRadius(radius); Vector l; ProgressChangedEvent lce = new ProgressChangedEvent(this,100.0*nCalc/(double)TotalCalc); synchronized(this) {l=(Vector)L.clone();} if(l!=null)for (int i=0;i x[top]) return top; // start binary search int mx = top; int mn = 0; int k = (mx+mn)/2; boolean found = false; boolean foundnear = false; int ipos = -1; while (!found&&!foundnear){ if (value==x[k]){ ipos = k; found = true; } else{ if (x[k] > value) mx = k-1; else mn = k+1; if (mx > mn) k = (mx+mn)/2; else{ ipos = mn; if (x[ipos] == value) found = true; else foundnear = true; } } } if (flag == 1){ while (x[ipos] >= value){ if (ipos == 0) return ipos; ipos--; } if (found) ipos++; ipos = Misc.min(top, ipos); } else{ while (x[ipos] <= value){ if (ipos == top) return ipos ; ipos++; } if (found) ipos--; ipos = Misc.max(0, ipos); } return ipos; } public void run(Vector L,GeoRectangle rec){ search(L,rec); Vector l; ProgressChangedEvent lce = new ProgressChangedEvent(this,0.0); synchronized(this) {l = (Vector)L.clone(); } for (int i = 0; i < l.size();i++) { ((ProgressEventListener)l.elementAt(i)).progressChanged(lce); } } public void search(Vector L,GeoRectangle rec){ results=new Results(); int rTimes; totCal = totDat = totNC2 = totNHy = 0; rTimes = (int) ((radMax-radMin)/radInc + 1.0); double radius = radMin - radInc; double width=rec.getWidth(); double height=rec.getHeight(); double trad=radius; System.out.println("rtimes ="+rTimes+" r "+radius+" w"+width+" h "+height); for (int i = 0;i