private void fill_vehicle_and_pick_extra_kids(vehicle proper_car, cluster most_distant_cluster, int total_extra_seats) { int extra_seats = proper_car.getCapacity() - most_distant_cluster.get_size(); cluster closest_cluster = closest_group_to(most_distant_cluster); while (closest_cluster != null && extra_seats >= closest_cluster.get_size()) { extra_seats -= closest_cluster.get_size(); merge_groups(most_distant_cluster, closest_cluster); closest_cluster = closest_group_to(most_distant_cluster); } fill_vehicle_with_all_kids_in_cluster(proper_car, most_distant_cluster); if (extra_seats > 0 && closest_cluster != null && !(extra_seats < total_extra_seats && extra_seats < 0.2 * proper_car.getCapacity() && most_distant_cluster.distance_to(closest_cluster) > ave_distance_in_groups)) { pull_appropriate_kids(proper_car, most_distant_cluster, closest_cluster, extra_seats); } }
private void fill_vehicle_and_reset_clusters(vehicle proper_car, List <vehicle> vehicles, cluster most_distant_cluster) { if (proper_car.getCapacity() < most_distant_cluster.get_size()) { fill_vehicle_with_max_capacity(proper_car, vehicles, most_distant_cluster); } else { fill_vehicle_and_may_pull_extra_kids(proper_car, vehicles, most_distant_cluster); } }
//Authors: Keenen Cates, Simon Owens /// <summary> /// Tests to see if actual name, capacity, and kid_list match the constructed vehicle object. /// </summary> /// <param name="actual_name"></param> /// <param name="actual_capacity"></param> /// <param name="actual_kids"></param> /// <param name="expected_vehicle"></param> private void AssertVehicleEquals(int actual_capacity, string actual_name, HashSet <kid> actual_kids, vehicle expected_vehicle) { // Test for name Assert.AreEqual(actual_name, expected_vehicle.getName()); // Test for capacity Assert.AreEqual(actual_capacity, expected_vehicle.getCapacity()); // Test for list of kids CollectionAssert.AreEqual(actual_kids.ToList(), expected_vehicle.getKids().ToList()); }
private void fill_vehicle_and_may_pull_extra_kids(vehicle proper_car, List <vehicle> vehicles, cluster most_distant_cluster) { int total_extra_seats = current_total_capacity_of(vehicles) - current_size_of_clusters(); cluster closest_cluster = closest_group_to(most_distant_cluster); int extra_seats = proper_car.getCapacity() - most_distant_cluster.get_size(); if (closest_cluster == null || extra_seats == 0) { fill_vehicle_with_all_kids_in_cluster(proper_car, most_distant_cluster); } else { if (extra_seats < total_extra_seats && extra_seats < 0.2 * proper_car.getCapacity() && most_distant_cluster.distance_to(closest_cluster) > ave_distance_in_groups) { fill_vehicle_with_all_kids_in_cluster(proper_car, most_distant_cluster); } else { fill_vehicle_and_pick_extra_kids(proper_car, most_distant_cluster, total_extra_seats); } } }
private void fill_vehicle_with_appropriate_kids(vehicle proper_car, cluster most_distant_cluster, cluster closest_cluster) { List <location> left_kids = new List <location>(); //List<location> selected_kids = new List<location>(); int extra_kids = most_distant_cluster.get_size() - proper_car.getCapacity(); while (extra_kids > 0) { location closest = find_closest_location(most_distant_cluster, closest_cluster); left_kids.Add(closest); most_distant_cluster.remove(closest); extra_kids--; } proper_car.fill_kids(most_distant_cluster.get_cluster()); most_distant_cluster.remove_all(); most_distant_cluster.add_range(left_kids); }