use crate::clustering::Centers;
use crate::space::{Point,ColoredMetric};
use crate::types::{PointCount,Distance};
pub(crate) fn gonzalez_heuristic<M : ColoredMetric>(space : &M, k : PointCount) -> Centers {
let mut gonzalez : Centers = Centers::with_capacity(k);
let first_center = space.point_iter().as_slice().first().expect("No points in metric.");
gonzalez.push(first_center);
let mut dist_x_center : Vec<Distance> = Vec::with_capacity(space.n());
for i in space.point_iter() {
dist_x_center.push(space.dist(first_center,i)); }
for i in 1..k {
let mut current_distance = <Distance>::MIN; let mut current_point : Option<&Point> = None; for (j, p) in space.point_iter().enumerate(){
let dist_to_newest_center = space.dist(p, gonzalez.get(i-1,space));
if dist_to_newest_center < dist_x_center[j] {
dist_x_center[j] = dist_to_newest_center;
}
if dist_x_center[j] > current_distance {
current_distance = dist_x_center[j];
current_point = Some(p);
}
}
gonzalez.push(current_point.expect("No new center could be found, i.e., current_point = None"));
}
gonzalez
}