Пример #1
0
        private void LoadData()
        {
            MPCLSPParser parser = new MPCLSPParser();

            Problem = new MPCLSP();
            MPCLSPSet dataset = new MPCLSPSet();

            string Path              = Environment.CurrentDirectory + "\\Dataset";
            string SC_ST_PC_PT       = Path + "\\SC-ST-PC-PT.txt";
            string TransferCostPath  = Path + "\\TransferCost.txt";
            string InventoryCostPath = Path + "\\InventoryCost.txt";
            string PeriodPath        = Path + "\\Period-Capacity.txt";


            parser.SC_ST_PC_PT(SC_ST_PC_PT);
            parser.TransferCost(TransferCostPath);
            parser.InventoryCost(InventoryCostPath);
            parser.Period(PeriodPath);

            Problem = ((MPCLSP)parser.Problem).Copy();


            double cost = Problem.ProductProductionCostFromPeriod2Period(1, 1, 1);

            double sc_pp = Problem.SetupCostOnPlant(1, 1);
            double st_pp = Problem.SetupTimeInPlant(1, 1);

            double pc_pp = Problem.ProductionCostOnPlant(1, 1);
            double pt_pp = Problem.ProcessingTimeInPlant(1, 1);

            Problem.DataSet.Periods[1].ProductionQuantity.Add(new PP()
            {
                Plant = Problem.DataSet.Plants[0], Product = Problem.DataSet.Products[0]
            }, 20);
            Problem.DataSet.Periods[1].ProductionQuantity.Add(new PP()
            {
                Plant = Problem.DataSet.Plants[1], Product = Problem.DataSet.Products[0]
            }, 20);
            Problem.DataSet.Periods[1].ProductionQuantity.Add(new PP()
            {
                Plant = Problem.DataSet.Plants[2], Product = Problem.DataSet.Products[0]
            }, 20);

            int pc = Problem.DataSet.Periods[1].ProductProductionQuantity(1);


            int            d_iut    = Problem.ProductDemandOnPlantFromPeriod2Period(1, 1, 1, 6);
            int            PD_jut   = Problem.PlantDemandFromPeriod2Period(1, 1, 1);
            int            D_iut    = Problem.ProductDemandFromPeriod2Period(1, 1, 6);
            MPCLSPSolution solution = new MPCLSPSolution()
            {
                Dataset = Problem.DataSet
            };
            MyILS_MPCLSP heuristic = new MyILS_MPCLSP();

            heuristic.Execute(Problem);
        }
Пример #2
0
        private double ObjectiveII(MPCLSPSolution solution)
        {
            MPCLSPSet dataset = solution.Dataset;
            double    cost    = 0.0;

            //foreach (var schadule in solution.Schedules)
            //{
            //    cost += dataset.Plants[schadule.Value.Plant].ProductionCost[schadule.Value.Product] * dataset.Periods[schadule.Value.Period].ProductionQuantity.ToList().Find
            //        (p => p.Key.Plant.UID == schadule.Value.Plant && p.Key.Product.UID == schadule.Value.Product).Value;
            //}
            return(cost);
        }
Пример #3
0
 /// <summary>
 /// Calculating weight for each product based on setup cost and setup time over different palnts
 /// </summary>
 /// <param name="dataset"></param>
 private void SetupWeight(MPCLSPSet dataset)
 {
     dataset.Products.ForEach(product =>
     {
         ((MPCLSPSolution)_problem.Solution).Dataset.Plants.ForEach(plant =>
         {
             plant.SetupWeghit.Add(new Tuple <double, int>
                                       (plant.SetupCost[product.UID] * plant.SetupTime[product.UID],
                                       product.UID));
         });
     });
 }
Пример #4
0
        private void HeuristicPreProcessing()
        {
            MPCLSPSet dataset = ((MPCLSPSolution)_problem.Solution).Dataset;

            //Setup Cost x Setup Time
            SetupWeight(dataset);
            //(Production Cost x Production Time) / Product Demand)
            ProductionWeight(dataset);
            //setup weight + production weight / product demand on plant
            DemandWeight(dataset);
            //Finding the best plant to setup product
            BestPlantToSetupProduct(dataset);
        }
Пример #5
0
 /// <summary>
 /// Finding the best plant to setup product based on ratio between setup cost and setup time
 /// </summary>
 /// <param name="dataset"></param>
 private static void BestPlantToSetupProduct(MPCLSPSet dataset)
 {
     dataset.Periods.ForEach(period =>
     {
         period.DemandWeghit = period.DemandWeghit.OrderBy(d => d.Item1).ToList();
         int best_plant      = 0;
         dataset.Products.ForEach(product =>
         {
             best_plant = period.BestPlantToSetup(product.UID);
             period.BestPP.Add(new Tuple <int, int>(best_plant, product.UID));
         });
     });
 }
Пример #6
0
        private void HeuristicScheduling()
        {
            MPCLSPSet dataset = ((MPCLSPSolution)_problem.Solution).Dataset;

            dataset.Periods.ForEach(period =>
            {
                Schedule schedule = null;
                MPCLSPPlant plant = null;
                int capacity      = 0;
                period.BestPP.ForEach(bpp =>
                {
                    if (schedule == null)
                    {
                        schedule         = new Schedule();
                        schedule.Dataset = dataset;
                        schedule.Period  = period.UID;
                        if (plant == null)
                        {
                            plant = dataset.Plants.Find(p => p.UID == bpp.Item1);
                            schedule.Plants.Add(plant.UID);
                            capacity = period.Capacity[plant.UID];
                        }
                    }

                    int pdp = period.ProductDemandInPeriod(bpp.Item2);
                    if (capacity > pdp)
                    {
                        plant.InstalledProducts.Add(bpp.Item2);
                        schedule.ProductionQuantity.Add(bpp.Item2, pdp);
                        capacity -= pdp;
                    }
                    else
                    {
                        plant.FullField    = true;
                        plant.LeftCapacity = capacity;
                        plant = dataset.Plants.Find(new_plant => new_plant.UID == plant.BestNeighborPlant());
                        schedule.Plants.Add(plant.UID);
                        plant.InstalledProducts.Add(bpp.Item2);
                        capacity = period.Capacity[plant.UID];
                    }
                });
                ((MPCLSPSolution)_problem.Solution).Schedules.Add(period.UID, schedule);
            });
        }
Пример #7
0
 /// <summary>
 /// Demand weight based on each period and plant and product (setup weight, production weight and demand on plant)
 /// </summary>
 /// <param name="dataset"></param>
 private static void DemandWeight(MPCLSPSet dataset)
 {
     dataset.Periods.ForEach(period =>
     {
         period.Demands.ToList().ForEach(demand =>
         {
             MPCLSPProduct product = demand.Key.Product;
             MPCLSPPlant plant     = demand.Key.Plant;
             int dv        = demand.Value;
             double weight = (plant.SetupWeghit.Find(p => p.Item2 == product.UID).Item1 +
                              plant.ProductionWeghit.Find(p => p.Item2 == product.UID).Item1) / dv;
             Tuple <double, PP> dw = new Tuple <double, PP>(weight, new PP()
             {
                 Plant = demand.Key.Plant, Product = demand.Key.Product
             });
             period.DemandWeghit.Add(dw);
         });
     });
 }
Пример #8
0
        private double ObjectiveI(MPCLSPSolution solution)
        {
            MPCLSPSet dataset     = solution.Dataset;
            double    score       = 0.0;
            double    Tstock_cost = 0.0;                                                                                                                     //Total stock cost

            foreach (var product in dataset.Products)                                                                                                        //Presented by i
            {
                foreach (var plant in dataset.Plants)                                                                                                        //Presented by j
                {
                    foreach (var period in dataset.Periods)                                                                                                  //Presented by t
                    {
                        int    I_ijt          = period.Stock.Where(p => p.Key.Product.UID == product.UID && p.Key.Plant.UID == plant.UID).First().Value;     //Stock of product i at plant j at the end of period t
                        double h_ijt          = period.StockCost.Where(p => p.Key.Product.UID == product.UID && p.Key.Plant.UID == plant.UID).First().Value; //Stock cost (unitary holding cost) of product i at plant j at the end of period t
                        double Ttransfer_cost = 0.0;                                                                                                         //Total transfer cost

                        foreach (var r_ijkt in plant.TransferCost)
                        {
                            int W_ijkt = 0;                             //Transfer quantity of product i from plant j to plant k in period t
                            KeyValuePair <PPP, int> transfer_quantity = period.TransferQuantity.ToList().Find(p =>
                                                                                                              p.Key.Product.UID == product.UID && p.Key.PlantJ.UID == plant.UID && p.Key.PlantK.UID == r_ijkt.Key);
                            W_ijkt = transfer_quantity.Value;

                            Ttransfer_cost += r_ijkt.Value * W_ijkt;     //Unitary transfer cost of product i from plant j to plant k in period t * transfer quantity of product i from plant j to plant k in period t
                        }
                        Tstock_cost += Ttransfer_cost + (h_ijt * I_ijt); //Stock cost of product i * Number of stoced + (Transfer cost in all periods * Number of transfers in all periods)
                    }
                }
            }

            double Tsetup_cost = 0.0;    //Total setup cost for all families that are in schedule

            foreach (var schedule in solution.Schedules)
            {
                Tsetup_cost += schedule.Value.TotalCost;
            }
            score = Tsetup_cost + Tstock_cost; //Total setup cost + Total stock cost
            return(score);
        }
Пример #9
0
 public MPCLSPSolution()
 {
     _dataset  = new MPCLSPSet();
     Schedules = new Dictionary <int, Schedule>();
 }
Пример #10
0
 private MPCLSPSolution(MPCLSPSolution instance)
 {
     _dataset  = instance.Dataset.Copy();
     Schedules = new Dictionary <int, Schedule>();
     instance.Schedules.ToList().ForEach(s => Schedules.Add(s.Key, s.Value.Copy()));
 }
Пример #11
0
 public MPCLSP()
 {
     Solution = new MPCLSPSolution();
     DataSet  = new MPCLSPSet();
 }