public Demand(Demand copy) { this.ID = copy.ID; this.GettingDate = copy.GettingDate; this.FinishingDate = copy.FinishingDate; this.ShouldBeDoneDate = copy.ShouldBeDoneDate; this.Urgency = copy.Urgency; this.Products = new ProductCluster(copy.Products); }
public Demand ModifyDemand(Demand[] demands, DateTime currentDate) { var arctProbabilities = uGen.GenerateSequence().GetEnumerator(); var urgProbabilities = uGen.GenerateSequence().GetEnumerator(); Func<IEnumerator<double>, double> getNext = (sequence) => { sequence.MoveNext(); return sequence.Current; }; var probabilitiesByProduct = new Dictionary<int, IEnumerator<double>>() { {1, this.firstArticleModifyGen.GenerateSequence().GetEnumerator()}, {2, this.secondArticleModifyGen.GenerateSequence().GetEnumerator()}, {3, this.thirdArticleModifyGen.GenerateSequence().GetEnumerator()}, }; var rand = new Random(Guid.NewGuid().GetHashCode()); var returnDemand = new Demand(); bool modifyFlag = false; while (!modifyFlag) { int i = rand.Next(demands.Length); var modifiedDemand = new Demand(demands[i]); if (modifiedDemand.Urgency == 2) throw new Exception("Заявка от которой отказались не может быть изменена!"); TimeSpan dt = currentDate.Subtract(demands[i].GettingDate); var demand = demands[i]; if (this.articlesModifyGen.GetProbability(dt.TotalMinutes) >= getNext(arctProbabilities)) { bool changeFlag = false; while (changeFlag == false) { var productClaster = new ProductCluster(); for (var productIndex = 1; productIndex <= 3; productIndex++) { int modifiedArticleNum = 0; demand.Products.GetProduct(productIndex, out modifiedArticleNum); modifiedArticleNum += (int)Math.Round(getNext(probabilitiesByProduct[productIndex])); if (modifiedArticleNum < 0) modifiedArticleNum = 0; if (!demand.Products.CompareProduct(productIndex, modifiedArticleNum)) changeFlag = true; productClaster.AddProduct(productIndex, modifiedArticleNum); } if (changeFlag && productClaster.CompareNomenclatureIsMore(demand.Products)) { modifiedDemand.Products.CleanProductsCluster(); modifiedDemand.Products.AddProductCluster(productClaster); modifyFlag = true; } } } if (demand.Urgency == 1) { if (this.urgToStandModifyGen.GetProbability(dt.TotalMinutes) >= getNext(urgProbabilities)) { modifiedDemand.Urgency = 0; //modifyFlag = true; срочность изменяется но если не изменились продукты изменение не произошло } } else { if (this.standToUrgModifyGen.GetProbability(dt.TotalMinutes) >= getNext(urgProbabilities)) { modifiedDemand.Urgency = 1; //modifyFlag = true; срочность изменяется но если не изменились продукты изменение не произошло } } if (modifyFlag) returnDemand = modifiedDemand; } return returnDemand; }
//public CDemand[] generateDemands(DateTime dt) //{ // int[] requestTimes = this.requestTimeGen.generateForDay(); // double[] firstArticlesSeq = this.firstArticleGen.generateN(requestTimes.Length); // double[] secondArticlesSeq = this.secondArticleGen.generateN(requestTimes.Length); // double[] thirdArticlesSeq = this.thirdArticleGen.generateN(requestTimes.Length); // int[] urgency = generateUrgencyRefuse(requestTimes.Length); // List<int> firstAricles = new List<int>(); // foreach (double i in firstArticlesSeq) // { // firstAricles.Add((int)Math.Round(i)); // } // List<int> secondAricles = new List<int>(); // foreach (double i in secondArticlesSeq) // { // secondAricles.Add((int)Math.Round(i)); // } // List<int> thirdAricles = new List<int>(); // foreach (double i in thirdArticlesSeq) // { // thirdAricles.Add((int)Math.Round(i)); // } // List<CDemand> demands = new List<CDemand>(); // int minutes = 0; // for (int i = 0; i < requestTimes.Length; i++) // { // minutes = minutes + requestTimes[i]; // /* // demands.Add(new CDemand(0,dt.AddMinutes(minutes), urgency[i], new Dictionary<int, int> { // { 1, firstAricles.ElementAt(i) }, // { 2, secondAricles.ElementAt(i) }, // { 3, thirdAricles.ElementAt(i) } // })); // */ // //---> // CProductCluster productCluster = new CProductCluster(); // //Дима: очень странно, но thirdAricles.ElementAt(i) иногда выдает ОТРИЦАТЕЛЬНОЕ число!!! // //вставил проверки на неотрицательность. // if (firstAricles.ElementAt(i)>0) // productCluster.AddProduct(1, firstAricles.ElementAt(i)); // if (secondAricles.ElementAt(i) > 0) // productCluster.AddProduct(2, secondAricles.ElementAt(i)); // if (thirdAricles.ElementAt(i) > 0) // productCluster.AddProduct(3, thirdAricles.ElementAt(i)); // demands.Add(new CDemand(0,dt.AddMinutes(minutes), urgency[i], productCluster)); // //<--- // } // return demands.ToArray(); //} /// <summary> /// генерация массива заявок /// </summary> /// <param name="dt"></param> /// <returns></returns> public Demand[] GenerateDemands(DateTime dt) { int[] requestTimes = this.requestTimeGen.GenerateForDay(); double[][] articlesModifyGen = new double[3][]; //собственно генерация articlesModifyGen[0] = this.firstArticleGen.GenerateN(requestTimes.Length); articlesModifyGen[1] = this.firstArticleGen.GenerateN(requestTimes.Length); articlesModifyGen[2] = this.firstArticleGen.GenerateN(requestTimes.Length); int[] urgency = GenerateUrgencyRefuse(requestTimes.Length); Demand[] demands = new Demand[requestTimes.Length]; int minutes = 0; //цикл по заявкам for (int iDemandNumber = 0; iDemandNumber < requestTimes.Length; iDemandNumber++) { minutes = minutes + requestTimes[iDemandNumber]; ProductCluster productCluster = new ProductCluster(); //заполнение кластера продуктов for (int iProductNumber = 1; iProductNumber <= Params.PRODUCTS_NUMBER; iProductNumber++) { if (articlesModifyGen[iProductNumber - 1][iDemandNumber] > 0) { productCluster.AddProduct(iProductNumber, (int)Math.Round(articlesModifyGen[iProductNumber - 1][iDemandNumber])); } } demands[iDemandNumber] = new Demand(0, dt.AddMinutes(minutes), urgency[iDemandNumber], productCluster); } return demands; }
public bool saveNewFrontDemands(Modeling.FrontOffice.Order[] newFrontOrders) { foreach(Modeling.FrontOffice.Order order in newFrontOrders) { int urg=0; if (order.isExpress==true) urg=1; /* CDemand demand = new CDemand(order.OrderID, this.modelTime, urg, new Dictionary<int, int> { { 1, order.ProductCount[0] }, { 2, order.ProductCount[1] }, { 3, order.ProductCount[2] } }); */ //---> ProductCluster productCluster = new ProductCluster(); for (int iProductNumber = 1; iProductNumber <= Params.PRODUCTS_NUMBER; iProductNumber++) { productCluster.AddProduct(iProductNumber, order.ProductCount[iProductNumber - 1 ]); } Demand demand = new Demand(order.OrderID, this.modelTime, urg, productCluster); //<--- demand.ShouldBeDoneDate = order.doneDate; bool addResult = this.storage.AddAcceptedDemand(demand); if (addResult==false) return false; } return true; }
public bool saveChangedFrontDemands(Modeling.FrontOffice.Order[] changedFrontOrders) { foreach (Modeling.FrontOffice.Order order in changedFrontOrders) { int urg = 0; if (order.isExpress == true) urg = 1; ProductCluster productCluster = new ProductCluster(); for (int iProductNumber = 1; iProductNumber <= Params.PRODUCTS_NUMBER; iProductNumber++) { productCluster.AddProduct(iProductNumber, order.ProductCount[iProductNumber - 1]); } Demand demand = new Demand(order.OrderID, new DateTime(), urg, productCluster); demand.ShouldBeDoneDate = order.doneDate; bool changeResult = this.storage.ModifyDemand(demand); if (changeResult == false) return false; } return true; }
/// <summary> /// изменить заявку в <see cref="acceptedDemands"/> /// </summary> /// <param name="modifiedDemand"></param> /// <returns></returns> public bool ModifyDemand(Demand modifiedDemand) { if (!acceptedDemands.ContainsKey(modifiedDemand.ID)) return ModelError.Error(); var acceptedDemand = this.acceptedDemands[modifiedDemand.ID]; //acceptedDemand.m_iUrgency = modifiedDemand.m_iUrgency; срочность нельзя изменить acceptedDemand.ShouldBeDoneDate = modifiedDemand.ShouldBeDoneDate; /* //add product cluster for (int iProductNumber = 1; iProductNumber < CParams.PRODUCTS_NUMBER + 1; iProductNumber++) { acceptedDemand.m_products[iProductNumber] = modifiedDemand.m_products[iProductNumber]; } */ //---> acceptedDemand.Products.CleanProductsCluster(); acceptedDemand.Products.AddProductCluster(modifiedDemand.Products); //<--- return true; }
/// <summary> /// Получить утверждённую заявку по id /// </summary> /// <param name="ind"></param> /// <param name="demand"></param> /// <returns></returns> public bool GetAcceptedDemand(int ind, out Demand demand) { demand = new Demand(); if (!acceptedDemands.ContainsKey(ind)) return ModelError.Error(); //ВАЖНО! Возможно здесь надо принудительно вызвать деструктор для demand // demand = new Demand(this.acceptedDemands[ind]); return true; }
/// <summary> /// Добавление новой заявки в список отклонённых /// </summary> /// <param name="demand"></param> /// <returns></returns> public bool AddDeclinedDemand(Demand demand) { if (declinedDemands.ContainsKey(demand.ID)) return ModelError.Error(); declinedDemands.Add(demand.ID, demand); return true; }
/// <summary> /// Добавление новой заявки в список отменённых /// </summary> /// <param name="id"></param> /// <returns></returns> public bool AddCanceledDemand(int id) { if (acceptedDemands.ContainsKey(id)) ModelError.Error(); var demand = new Demand(acceptedDemands[id]); var demandPlanElementReports = this.planReport.Values.Where(x => x.PlanElement.DemandID == demand.ID); foreach (PlanReportElement c in demandPlanElementReports) { c.PlanElement.DemandID = -1; } acceptedDemands.Remove(id); if (canceledDemands.ContainsKey(id)) return ModelError.Error(); canceledDemands.Add(demand.ID, demand); return true; }
/* private Queue<CDeliveryDemand> m_newDeliveryDemands = new Queue<CDeliveryDemand>(); // заявки на поставку материалов, пришедшие от back office и ещё не обработанные */ /// <summary> /// Добавление новой заявки в список принятых /// </summary> /// <param name="demand"></param> /// <returns></returns> public bool AddAcceptedDemand(Demand demand) { if (acceptedDemands.ContainsKey(demand.ID)) return ModelError.Error(); acceptedDemands.Add(demand.ID, demand); return true; }