Ejemplo n.º 1
0
 private vehicle find_appropriate_vehicle_to(cluster most_distant_cluster, List <vehicle> vehicles)
 {
     foreach (vehicle v in vehicles)
     {
         if (!v.has_filled_kids() && v.getCapacity() >= most_distant_cluster.get_size())
         {
             return(v);
         }
     }
     return(find_largest_unfilled_car(vehicles));
 }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
0
 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);
     }
 }
Ejemplo n.º 4
0
        public double distance_to(cluster B)
        {
            double total = 0;

            foreach (location a in group)
            {
                double ave_d = 0;
                foreach (location b in B.get_cluster())
                {
                    ave_d += a.distance_to(b);
                }
                ave_d /= B.get_size();
                total += ave_d;
            }
            total /= size;
            return(total);
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        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);
                }
            }
        }