Ejemplo n.º 1
0
        /// <summary>
        /// Will return the quantity of product i produced at plant j in all periods
        /// </summary>
        /// <param name="plant">Plant</param>
        /// <param name="product">Product</param>
        /// <returns>Total X_ijT</returns>
        public int DemandInPeriods(MPCLSPPlant plant, MPCLSPProduct product)
        {
            int demand = 0;

            DataSet.Periods.ForEach(p => p.Demands.Where(item => item.Key.Plant.UID == plant.UID && item.Key.Product.UID == product.UID).ToList().ForEach(d => demand += d.Value));
            return(demand);
        }
Ejemplo n.º 2
0
        public void Period(string path)
        {
            System.IO.StreamReader file = new System.IO.StreamReader(path);
            string str = file.ReadLine();

            int products = int.Parse((str.Trim().Split('/')[2]));
            int plants   = int.Parse(str.Trim().Split('/')[1]);
            int periods  = int.Parse(str.Trim().Split('/')[0]);

            for (int t = 1; t <= periods; t++)
            {
                str = file.ReadLine();
                if (str == "")
                {
                    t--; continue;
                }

                MPCLSPPeriod period = new MPCLSPPeriod(t, new Dictionary <int, int>());
                _problem.DataSet.Periods.Add(period);
                String[] capacities = str.Trim().Split('\t');

                for (int j = 1; j <= plants; j++)
                {
                    MPCLSPPlant plant = _problem.DataSet.Plants.Find(p => p.UID == j);
                    plant.Lines.FirstOrDefault().Capacity = int.Parse(capacities[j - 1]);
                    period.Capacity.Add(plant.UID, plant.Capacity);
                    period.Plants.Add(plant);
                    str = file.ReadLine();
                    string[] costs = str.Trim().Split('\t');

                    for (int i = 1; i <= products; i++)
                    {
                        MPCLSPProduct product = _problem.DataSet.Products.Find(p => p.UID == i);
                        product.TotalDemand += int.Parse(costs[i - 1]);
                        period.Demands.Add(new PP()
                        {
                            Product = product, Plant = plant
                        }, int.Parse(costs[i - 1]));
                        period.Stock.Add(new PP()
                        {
                            Product = product, Plant = plant
                        }, 0);
                        period.StockCost.Add(new PP()
                        {
                            Product = product, Plant = plant
                        }, 1.0);
                        //period.TransferQuantity.Add(new PPP() { Product = product, PlantJ = plant, PlantK = plant }, 0);
                    }
                }
            }
        }
Ejemplo n.º 3
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);
            });
        }
Ejemplo n.º 4
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);
         });
     });
 }
Ejemplo n.º 5
0
        public void TransferCost(string path)
        {
            System.IO.StreamReader file = new System.IO.StreamReader(path);
            string str    = file.ReadLine();
            int    plants = int.Parse(str.Trim().Split('/')[0]);

            for (int i = 1; i <= plants; i++)
            {
                str = file.ReadLine();
                if (str == "")
                {
                    i--; continue;
                }

                string[]    costs = str.Trim().Split('\t');
                MPCLSPPlant plant = _problem.DataSet.Plants.Find(p => p.UID == i);
                for (int j = 1; j <= plants; j++)
                {
                    plant.TransferCost.Add(j, double.Parse(costs[j - 1]));
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Will return the setup time for product i on plant
        /// </summary>
        ///<param name = "plant_uid" >Plant Id</param>
        /// <param name="product_uid">Product Id</param>
        /// <returns>ST_ij</returns>
        public double SetupTimeInPlant(int plant_uid, int product_uid)
        {
            MPCLSPPlant plant = DataSet.Plants.Find(p => p.UID == plant_uid);

            return(plant.SetupTime[product_uid]);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Will return the production cost for product i on plant
        /// </summary>
        ///<param name = "plant_uid" >Plant Id</param>
        /// <param name="product_uid">Product Id</param>
        /// <returns>PC_ij</returns>
        public double ProductionCostOnPlant(int plant_uid, int product_uid)
        {
            MPCLSPPlant plant = DataSet.Plants.Find(p => p.UID == plant_uid);

            return(plant.ProductionCost[product_uid]);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Will return the processing time for product i on plant
        /// </summary>
        ///<param name = "plant_uid" >Plant Id</param>
        /// <param name="product_uid">Product Id</param>
        /// <returns>PT_ij</returns>
        public double ProcessingTimeInPlant(int plant_uid, int product_uid)
        {
            MPCLSPPlant plant = DataSet.Plants.Find(p => p.UID == plant_uid);

            return(plant.ProcessingTimes[product_uid]);
        }
Ejemplo n.º 9
0
        public void SC_ST_PC_PT(string path)
        {
            System.IO.StreamReader file = new System.IO.StreamReader(path);
            string str = file.ReadLine();

            int products = int.Parse((str.Trim().Split('/')[0]));
            int plants   = int.Parse(str.Trim().Split('/')[1]);

            //Products
            for (int i = 1; i <= products; i++)
            {
                MPCLSPProduct product = new MPCLSPProduct(i);
                MPCLSPFamily  family  = new MPCLSPFamily(i);
                family.Products.Add(product);
                _problem.DataSet.Families.Add(family);
                _problem.DataSet.Products.Add(product);
            }

            //Setup Cost
            for (int j = 1; j <= plants; j++)
            {
                str = file.ReadLine();
                if (str == "")
                {
                    j--; continue;
                }
                string[]   costs = str.Trim().Split('\t');
                MPCLSPLine line  = new MPCLSPLine(j)
                {
                    Families = new List <MPCLSPFamily>()
                };
                MPCLSPPlant plant = new MPCLSPPlant(j, new List <MPCLSPLine>()
                {
                    line
                });

                _problem.DataSet.Plants.Add(plant);
                for (int i = 1; i <= products; i++)
                {
                    MPCLSPProduct product = _problem.DataSet.Products.Find(p => p.UID == i);
                    line.Products.Add(product);
                    plant.Products.Add(product);
                    plant.SetupCost.Add(product.UID, double.Parse(costs[i - 1]));
                }
            }

            //Setup Time
            for (int j = 1; j <= plants; j++)
            {
                str = file.ReadLine();
                if (str == "")
                {
                    j--; continue;
                }
                string[]    costs = str.Trim().Split('\t');
                MPCLSPPlant plant = _problem.DataSet.Plants.Find(p => p.UID == j);
                for (int i = 1; i <= products; i++)
                {
                    plant.SetupTime.Add(i, int.Parse(costs[i - 1]));
                }
            }

            //Production Cost
            for (int j = 1; j <= plants; j++)
            {
                str = file.ReadLine();
                if (str == "")
                {
                    j--; continue;
                }
                string[]    costs = str.Trim().Split('\t');
                MPCLSPPlant plant = _problem.DataSet.Plants.Find(p => p.UID == j);
                for (int i = 1; i <= products; i++)
                {
                    plant.ProductionCost.Add(i, double.Parse(costs[i - 1]));
                }
            }

            //Processing Time
            for (int j = 1; j <= plants; j++)
            {
                str = file.ReadLine();
                if (str == "")
                {
                    j--; continue;
                }
                string[]    costs = str.Trim().Split('\t');
                MPCLSPPlant plant = _problem.DataSet.Plants.Find(p => p.UID == j);
                for (int i = 1; i <= products; i++)
                {
                    plant.ProcessingTimes.Add(i, int.Parse(costs[i - 1]));
                }
            }
        }