예제 #1
0
        private location find_closest_location(cluster target_cluster, cluster adjacent_cluster)
        {
            double   d      = 9999;
            location target = null;

            foreach (location each in target_cluster.get_cluster())
            {
                cluster c = new cluster(each);
                if (c.distance_to(adjacent_cluster) < d)
                {
                    d      = c.distance_to(adjacent_cluster);
                    target = each;
                }
            }
            return(target);
        }
예제 #2
0
        public void grouping()
        {
            int c = 0;

            groups = new List <cluster>();
            foreach (location point in points)
            {
                if (point.get_cluster() == -1 && point.closest_place().get_cluster() == -1)
                {
                    if (point.closest_place().closest_place().Equals(point))
                    {
                        groups.Add(new cluster(new location[] { point, point.closest_place() }, c));
                        c++;
                    }
                }
            }

            if (c < 2)
            {
                location new_group = null;
                double   furthest  = 0;
                foreach (location point in points)
                {
                    if (point.get_cluster() == -1)
                    {
                        cluster p = new cluster(point);
                        double  d = 0;
                        foreach (cluster A in groups)
                        {
                            d = p.distance_to(A);
                            if (d > furthest)
                            {
                                furthest  = d;
                                new_group = point;
                            }
                        }
                    }
                }
                if (new_group != null)
                {
                    groups.Add(new cluster(new location[] { new_group }, c));
                }
                else
                {
                    groups.Clear();
                    c = 0;
                    foreach (location point in points)
                    {
                        groups.Add(new cluster(new location[] { point }, c));
                        c++;
                    }
                }
            }

            clustering();
        }
예제 #3
0
        private cluster closest_group_to(cluster o)
        {
            double  closest       = 9999;
            cluster closest_group = null;

            foreach (cluster group in groups)
            {
                if (!group.Equals(o))
                {
                    double d = o.distance_to(group); //distance_between_groups(o, group);
                    if (d < closest)
                    {
                        closest       = d;
                        closest_group = group;
                    }
                }
            }
            return(closest_group);
        }
예제 #4
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);
            }
        }
예제 #5
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);
                }
            }
        }