Skip to content
Snippets Groups Projects
Commit c37f720e authored by Christopher Schankula's avatar Christopher Schankula :earth_africa:
Browse files

first draft of (fast) clustering

parent d2004c92
No related branches found
No related tags found
No related merge requests found
......@@ -18,6 +18,7 @@ import search.BST;
import search.BasicSearch;
import search.BasicSearchResult;
import search.Histogram;
import search.RecordCluster;
import sort.Bound;
import sort.GeneralRange;
import sort.KDT;
......@@ -71,6 +72,11 @@ public class Main {
public static void init() {
System.out.println("Welcome!");
BasicSearchResult bsr = BasicSearch.range(159512, 1960, 2016);
ArrayList<RecordCluster> rc = (ArrayList<RecordCluster>) bsr.cluster(1000000);
System.out.println(rc.size());
while(true) {
System.out.println("Main Menu");
System.out.println("Available commands:");
......
......@@ -65,6 +65,6 @@ public class BasicSearch {
}
double time = sw.elapsedTime();
return new BasicSearchResult(results, time);
return new BasicSearchResult(taxonId, yearLo, yearHi, results, time);
}
}
package search;
import java.util.ArrayList;
import java.util.HashMap;
import data.Record;
<<<<<<< HEAD
import sort.Bound;
import sort.GeneralRange;
=======
import sort.RangeHelper;
import java.lang.Math;
>>>>>>> branch 'web' of git@gitlab.cas.mcmaster.ca:schankuc/2XB3.git
public class BasicSearchResult {
private final Integer taxonId;
private final Integer yearLo;
private final Integer yearHi;
private ArrayList<Record> results;
private final double time;
private BST<Integer, Integer> histogram;
private Integer sum;
private
public static void main(String[] args) {
//Graph g = new Graph();
}
public BasicSearchResult(ArrayList<Record> results, double time) {
public BasicSearchResult(Integer taxonId, Integer yearLo, Integer yearHi, ArrayList<Record> results, double time) {
this.taxonId = taxonId;
this.yearLo = yearLo;
this.yearHi = yearHi;
this.results = results;
this.time = time;
}
......@@ -53,19 +54,64 @@ public class BasicSearchResult {
return this.sum;
}
<<<<<<< HEAD
/**
*
* @param area
*/
public Iterable<RecordCluster> cluster(double area){
HashMap<String, Integer> nodeMap = new HashMap<String, Integer>();
HashMap<String, Boolean> marked = new HashMap<String, Boolean>();
int i = 0;
for(Record r: results) {
nodeMap.put(r.getOccurId(), i);
i++;
}
Graph G = new Graph(results.size());
double dist = Math.sqrt(area);
for (Record r: results) {
if (marked.get(r.getOccurId()) != null) continue;
double lat = r.getLatitude();
double lon = r.getLongitude();
BasicSearchResult res = BasicSearch.range(taxonId, yearLo, yearHi, lat - latRange(dist), lat + latRange(dist), lon - lngRange(dist,lat), lon + lngRange(dist,lat));
for (Record r1: res.results()) {
marked.put(r1.getOccurId(), true);
G.addEdge(nodeMap.get(r.getOccurId()), nodeMap.get(r1.getOccurId()));
}
}
System.out.println("Edges found");
CC cc = new CC(G);
ArrayList<RecordCluster> clusters = new ArrayList<RecordCluster>();
for(int j = 0; j < cc.count(); j++) {
clusters.add(new RecordCluster());
}
for (int j = 0; j < G.V(); j++) {
Integer component = cc.id(j);
clusters.get(component).addRecord(results.get(j));
}
return clusters;
}
private ArrayList<GeneralRange> ranges(double lat, double lon, double area){
ArrayList<GeneralRange>()
private ArrayList<GeneralRange<Record>> ranges(double lat, double lon, double area){
double dist = Math.sqrt(area);
ArrayList<GeneralRange<Record>> range = new ArrayList<GeneralRange<Record>>();
GeneralRange<Record> latRange = RangeHelper.latitude(Bound.LOWHIGH, lat - latRange(dist), lat + latRange(dist));
GeneralRange<Record> lonRange = RangeHelper.longitude(Bound.LOWHIGH, lon - lngRange(dist,lat), lon + lngRange(dist,lat));
return range;
}
=======
private double lngRange(double dist, double lat){
return dist/(Math.cos(lat)*222);
}
......@@ -73,6 +119,4 @@ public class BasicSearchResult {
private double latRange(double dist){
return (dist/111)/2;
}
>>>>>>> branch 'web' of git@gitlab.cas.mcmaster.ca:schankuc/2XB3.git
}
package search;
import java.util.ArrayList;
public class CC {
private boolean[] marked;
......
......@@ -9,6 +9,11 @@ public class RecordCluster {
private ArrayList<Record> records;
private Point centroid;
public RecordCluster() {
records = new ArrayList<Record>();
centroid = new Point(0,0);
}
public void addRecord(Record r) {
records.add(r);
}
......
package search;
import sort.GeneralCompare;
public class RedBlackTree<Key, Value> {
private Node<Key, Value> root; // Root of the tree
private GeneralCompare<Key> compare;
......@@ -39,11 +41,6 @@ public class RedBlackTree<Key, Value> {
h = h.left();
}
}
<<<<<<< HEAD
=======
>>>>>>> 459508d... get method added to redBlackTree
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment