Exemplo n.º 1
0
 public PFIH(Depo depo, Vehicle vehicle, List <Customer> customerList, double[][] cTocDistance)
 {
     this.depo         = depo;
     this.vehicle      = vehicle;
     this.customerList = customerList;
     this.noOfCustomer = customerList.Count;
     this.cTocDistance = cTocDistance;
 }
Exemplo n.º 2
0
 public SimulatedAnnealing(Depo depo, Vehicle vehicle, List <Customer> customerList, double[][] cTocDistance)
 {
     this.noOfCustomer = customerList.Count;
     this.depo         = depo;
     this.vehicle      = vehicle;
     this.customerList = customerList; //depo is included as first customer
     this.cTocDistance = cTocDistance; //depo is include as First customer
 }
Exemplo n.º 3
0
 public TabuSearch(Depo depo, Vehicle vehicle, List <Customer> customerList, double[][] cTocDistance)
 {
     this.depo         = depo;
     this.vehicle      = vehicle;
     this.customerList = customerList;
     this.cTocDistance = cTocDistance;
     this.noOfCustomer = customerList.Count;
     swapTabuList      = new List <SwapTabuMove>();
     insertionTabuList = new List <InsertionTabuMove>();
 }
Exemplo n.º 4
0
        //converting depo into customer
        public static Customer DepoAsCustomer(Depo depo)
        {
            Customer customer = new Customer();

            customer.id               = depo.id;
            customer.x_coordinate     = depo.x_coordinate;
            customer.y_coordinate     = depo.y_coorninate;
            customer.demand           = depo.demand;
            customer.timeWindow_start = depo.timeWindow_start;
            customer.timeWindow_end   = depo.timeWindow_end;
            customer.serviceTime      = depo.serviceTime;
            return(customer);
        }
Exemplo n.º 5
0
        //generating random solution(List<List<Customer>>)
        public static List <List <Customer> > GenerateRandomRouteList(Depo depo, Vehicle vehicle, List <Customer> customerList, double[][] cTocDistance)
        {
            //removing depo
            customerList.RemoveAt(0);

            List <List <Customer> > routeList            = new List <List <Customer> >();
            List <Customer>         unroutedCustomerList = new List <Customer>();

            unroutedCustomerList.AddRange(customerList);

            while (unroutedCustomerList.Count > 0)
            {
                List <Customer> currentRouteCustomerList = new List <Customer>();
                //adding depo as first customer
                currentRouteCustomerList.Add(DepoAsCustomer(depo));
                //adding depo as last customer
                currentRouteCustomerList.Add(DepoAsCustomer(depo));

                int  currentRouteCustomerIndex = 1;
                bool feasible = false;

                for (int unroutedCustomerIndex = 0; unroutedCustomerIndex < unroutedCustomerList.Count; unroutedCustomerIndex++)
                {
                    Customer unroutedCustomer = unroutedCustomerList[unroutedCustomerIndex];
                    currentRouteCustomerList.Insert(currentRouteCustomerIndex, unroutedCustomer);
                    feasible = CheckCapacityConstraint(currentRouteCustomerList, vehicle.capacity) &&
                               CheckTimeConstraint(currentRouteCustomerList, cTocDistance);
                    if (feasible)
                    {
                        unroutedCustomerList.RemoveAt(unroutedCustomerIndex);
                        currentRouteCustomerIndex++;
                    }
                    else
                    {
                        currentRouteCustomerList.RemoveAt(currentRouteCustomerIndex);
                    }
                }
                routeList.Add(currentRouteCustomerList);
            }
            return(routeList);
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            Depo            depo         = new Depo();
            Vehicle         vehicle      = new Vehicle();
            List <Customer> customerList = new List <Customer>();

            vehicle.id       = 0;
            vehicle.capacity = 200;
            bool isDepo     = true;
            int  customerId = 0;

            //Getting customer data from data.txt which contains data from soloman's dataset
            //URL for soloman's dataset http://web.cba.neu.edu/~msolomon/r101.htm (replace "  " with " " in data.txt)
            foreach (string line in File.ReadLines(@"/home/rahul/vscode-workspace/VRPTW/data.txt", Encoding.UTF8))
            {
                line.Trim();
                string[] data = line.Split(" ");
                if (isDepo)
                {
                    depo.id               = customerId++;
                    depo.x_coordinate     = double.Parse(data[2]);
                    depo.y_coorninate     = double.Parse(data[3]);
                    depo.demand           = double.Parse(data[4]);
                    depo.timeWindow_start = double.Parse(data[5]);;
                    depo.timeWindow_end   = double.Parse(data[6]);
                    depo.serviceTime      = double.Parse(data[7]);
                    isDepo = false;
                }
                else
                {
                    Customer customer = new Customer();
                    customer.id               = customerId++;
                    customer.x_coordinate     = double.Parse(data[2]);
                    customer.y_coordinate     = double.Parse(data[3]);
                    customer.demand           = double.Parse(data[4]);
                    customer.timeWindow_start = double.Parse(data[5]);;
                    customer.timeWindow_end   = double.Parse(data[6]);
                    customer.serviceTime      = double.Parse(data[7]);
                    customerList.Add(customer);
                    //Console.WriteLine(customer.x_coordinate+" "+ customer.y_coordinate+" "+ customer.demand+" "+ customer.timeWindow_start+" "+ customer.timeWindow_end);
                }
            }

            //inserting depo as customer at beggining
            customerList.Insert(0, Utils.DepoAsCustomer(depo));

            //calculating customer to customer distance (0 index represents depo)
            int noOfCustomer = customerList.Count;

            double[][] cTocDistance = new double[noOfCustomer][];
            for (int i = 0; i < noOfCustomer; i++)
            {
                cTocDistance[i] = new double[noOfCustomer];
                for (int j = 0; j < noOfCustomer; j++)
                {
                    cTocDistance[i][j] = Utils.CalculateDistance(customerList[i].x_coordinate,
                                                                 customerList[i].y_coordinate,
                                                                 customerList[j].x_coordinate,
                                                                 customerList[j].y_coordinate);
                }
            }

            //Calling Simulated Annealing
            SimulatedAnnealing simulatedAnnealing = new SimulatedAnnealing(depo, vehicle, customerList, cTocDistance);

            simulatedAnnealing.run(100, 1, 0.98, 6000);

            //Calling Tabu Search
            // TabuSearch tabuSearch = new TabuSearch(depo, vehicle, customerList, cTocDistance);
            // tabuSearch.run();
        }