-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
using dbscan clustering algorithm, all tests pass except clustiner to…
…o loosly on large grids
- Loading branch information
Showing
4 changed files
with
81 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from operator import attrgetter | ||
|
||
class Cluster: | ||
def __init__(self, label, destinations): | ||
self.destinations = destinations | ||
self.destination_closest_to_car = min(destinations, key=attrgetter('distance_from_car')) | ||
self.label = label | ||
self.size = len(destinations) | ||
|
||
def set_weight(self, normalized_size_weight, normalized_distance_weight): | ||
self.weight = normalized_size_weight + normalized_distance_weight |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,8 @@ | ||
from utils import Utils | ||
|
||
class Destination: | ||
def __init__(self, location, distance_from_car): | ||
def __init__(self, location, distance_from_car, cluster_label): | ||
self.location = location | ||
self.distance_from_car = distance_from_car | ||
self.cluster_weight = 0 | ||
|
||
|
||
def build_cluster_weight(self, destinations, closest_location_distance): | ||
distance_to_neighbors = [Utils.get_taxicab_distance(neighbor.location, self.location) for neighbor in destinations if neighbor.location != self.location] | ||
#let's say locations are clustered 'close' if they're closer to each other | ||
#than the otherwise nearest location is to the car | ||
close_neighbors = [neighbor_distance for neighbor_distance in distance_to_neighbors if neighbor_distance <= closest_location_distance] | ||
if close_neighbors: | ||
self.cluster_weight = len(close_neighbors) | ||
self.cluster_label = cluster_label | ||
|
||
def __eq__(self, other): | ||
return self.location == other.location and self.distance_from_car == other.distance_from_car and self.cluster_weight == other.cluster_weight | ||
return self.location == other.location and self.distance_from_car == other.distance_from_car |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters