Beispiel #1
0
        private Customer[] Generate(int amount)
        {
            /*
            if (clustered)
            {
                clusters = r.Next(2, 6);
                System.Console.WriteLine("Clusters: " + clusters);
            }
            else
            {
                clusters = 1;
                System.Console.WriteLine("Clusters: 1 grote cluster");
            }
            */
            int cnr = 1;

                for (int t = 0; t < amount ; t++)
                {
                    //int d = 1000 / clusters;
                    int x = r.Next(-1000, 1000);
                    int y = r.Next(-1000, 1000);
                    customers[cnr-1] = new Customer(x, y, cnr);
                    cnr++;
                    //System.Console.WriteLine("Customer " + cnr + ": X pos " + x + " , y pos " + y + " cluster: 1");
                }

            return customers;
        }
Beispiel #2
0
        public Solution NearestNeighbour(Customer[] customers, int deliverers)
        {
            Deliveryman[] d = new Deliveryman[deliverers];
            for (int t = 0; t < d.Length; t++)
            {
                d[t] = new Deliveryman();
            }

            Point cur_pos = new Point(0, 0);

            for (int x = 0; x < customers.Length / deliverers; x++)
            {
                int nearest_neighbour = -1;
                int best_dist = int.MaxValue;
                for (int t = 0; t < customers.Length; t++)
                {
                    if (!visited[t])
                    {
                        int dist = Math.Abs(customers[t].X - cur_pos.X) + Math.Abs(customers[t].Y - cur_pos.Y);
                        if (dist < best_dist)
                        {
                            nearest_neighbour = customers[t].ID;
                            best_dist = dist;
                        }
                    }
                }
                d[0].route.Add(nearest_neighbour);
                visited[nearest_neighbour - 1] = true;
                cur_pos = new Point(customers[nearest_neighbour - 1].X, customers[nearest_neighbour - 1].Y);
            }
            return new Solution(customers, d);
        }
Beispiel #3
0
        public Edge(Customer c1, Customer c2)
        {
            ID1 = c1.ID;
              ID2 = c2.ID;
              X1 = c1.X;
              X2 = c2.X;
              Y1 = c1.Y;
              Y2 = c2.Y;

              Helling();
        }
Beispiel #4
0
        public Solution EqualNeighbour(Customer[] customers, int deliverers)
        {
            Deliveryman[] ds = new Deliveryman[deliverers];
            for (int t = 0; t < ds.Length; t++)
            {
                ds[t] = new Deliveryman();
            }

            for (int x = 0; x < customers.Length; x++)
            {
                int laziest = int.MaxValue;
                Deliveryman l = null;
                foreach (Deliveryman d in ds)
                {
                    int score = 0;
                    Point cur_pos = new Point(0, 0);
                    foreach (int z in d.route)
                    {
                        int dist = Math.Abs(cs[z - 1].X - cur_pos.X) + Math.Abs(cs[z - 1].Y - cur_pos.Y);
                        score += dist;
                        cur_pos = new Point(cs[z - 1].X, cs[z - 1].Y);
                    }

                    score += Math.Abs(cur_pos.X - 0) + Math.Abs(cur_pos.Y - 0);
                    if (score < laziest)
                    { laziest = score; l = d; }
                }

                for (int t = 0; t < ds.Length; t++)
                {
                    if (ds[t] == l)
                        ds[t].route.Add(customers[x].ID);
                }
            }

            return new Solution(customers, ds);
        }
Beispiel #5
0
 public Solution(Customer[] customers, Deliveryman[] d)
 {
     // customers, or 'map' of the problem
       cs = customers;
       // representation of the routes, by customer id's
       rs = d;
       // number of deliverymen
       n = d.Length;
       // rnd
       rnd = new Random();
 }
Beispiel #6
0
        public Solution RandomMultiple(Customer[] customers, int amount)
        {
            Deliveryman[] work = new Deliveryman[amount];

            int path_length = 0;
            if (customers.Length % amount == 0)
                path_length = customers.Length / amount;
            else
                path_length = customers.Length / amount + 1;

            for (int t = 0; t < work.Length; t++)
            {
                work[t] = new Deliveryman();
            }

            //Random r = new Random();
            for (int t = 0; t < customers.Length; t++)
            {
                int x = r.Next(0, work.Length);
                work[x].route.Add(customers[t].ID);
            }

            return new Solution(customers, work);
        }