/// <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); }
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); } } } }
/// <summary>!!! /// Will return the production cost for product i from period u to period t in all plants /// </summary> /// <param name="product_uid">Product Id</param> /// <param name="period_t">Period u</param> /// <param name="period_u">Period t</param> /// <returns>Phi_fmut</returns> public double ProductProductionCostFromPeriod2Period(int product_uid, int period_t, int period_u) { double tCost = 0.0; int D_iut = 0; MPCLSPProduct product = DataSet.Products.Find(p => p.UID == product_uid); for (; period_t <= period_u; period_t++) { DataSet.Periods[period_t - 1].Demands.Where(d => d.Key.Product.UID == product_uid).ToList().ForEach(d => { double cost = 0.0; cost = d.Key.Plant.ProductionCost[product_uid]; D_iut += d.Value; tCost += cost * D_iut; }); } return(tCost); }
/// <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); }); }); }
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])); } } }