public DeliveryDemand(DeliveryDemand copy) { this.ID = copy.ID; this.IsDone = copy.IsDone; this.RealDeliveryDate = copy.RealDeliveryDate; this.FillDeliveryDate = copy.FillDeliveryDate; this.MaterialsDemand = new MaterialCluster(copy.MaterialsDemand); }
public DeliveryDemand[] ModifyDeliveries(DeliveryDemand[] deliveries) { List<DeliveryDemand> modifiedDeliveries = new List<DeliveryDemand>(); double[] deliveryDelaySeq = this.deliveryDelayGen.GenerateN(deliveries.Length); double[][] deliveryElementsModifySeq = new double[12][]; for (int i = 0; i < 12; i++) { deliveryElementsModifySeq[i] = this.deliveryElementsModifyGens[i].GenerateN(deliveries.Length); } for (int i = 0; i < deliveries.Length; i++) { DeliveryDemand modifiedDelivery = new DeliveryDemand(deliveries[i]); if (deliveryDelaySeq[i] > 0) modifiedDelivery.RealDeliveryDate = modifiedDelivery.FillDeliveryDate.AddMinutes((int)Math.Round(deliveryDelaySeq[i])); for (int j = 0; j < Params.MATERIALS_NUMBER; j++) { //***if (deliveries[i].m_materialsDemand[j + 1] != 0) if (deliveries[i].MaterialsDemand.IsMaterial(j + 1, 1)) //проверка есть ли в данной заявке на поставку хотя бы 1 материал номера (j + 1) { int mod = (int)Math.Round(deliveryElementsModifySeq[j][i]); if (mod > 0) { //***modifiedDelivery.m_materialsDemand[j + 1] = deliveries[i].m_materialsDemand[j + 1] - mod; modifiedDelivery.MaterialsDemand.CleanMaterial(j + 1); int iTemp = 0; deliveries[i].MaterialsDemand.GetMaterial(j + 1, out iTemp); iTemp -= mod; if (iTemp > 0) { modifiedDelivery.MaterialsDemand.AddMaterial(j + 1, iTemp); } } /*** if (modifiedDelivery.m_materialsDemand[j + 1] < 0) { modifiedDelivery.m_materialsDemand[j + 1] = 0; } */ } } /* List<DeliveryElement> delivElems = new List<DeliveryElement>(modifiedDelivery.deliveryElements); bool nullFlag = false; foreach (DeliveryElement dElem in delivElems) { if (dElem.num <= 0) { delivElems.Remove(dElem); nullFlag = true; } } if (nullFlag == true) modifiedDelivery.deliveryElements = delivElems.ToArray(); */ modifiedDeliveries.Add(modifiedDelivery); } return modifiedDeliveries.ToArray(); }
private void Iteration(Label label) { for (int i = this.currentModellingDay; i < this.modelingDays; i++) { this.currentModellingDay = i; if (this.stopFlag == true) { pauseDone.Set(); break; } DateTime workdayStartTime = startTime.AddDays(i); modelTime = workdayStartTime; int[] materialsNumToday = new int[12]; for (int j=0;j<12;j++) { //***materialsNumToday[j]=this.storage.GetMaterialNumberFromID(j+1); //возвращает со склада в materialsNumToday[j] количество материала с номером (j + 1) this.storage.Materials.GetMaterial(j + 1, out materialsNumToday[j]); } this.storage.AddMaterialsStatisticDay(materialsNumToday); Demand[] newDemands = this.generator.GenerateDemands(workdayStartTime); int[] modifyDemandsTime = this.generator.GenerateModifyTime(); ////////////////////////////////////////////////// Обращение к back-office this.storage.ClearAllPlan(); this.storage.AddDailyPlan(this.backOffice.GetDailyPlan(modelTime,ref this.storage)); int rem = -1; int span = (int)(modelTime-startTime).TotalDays; Math.DivRem(span,Params.DELIVERY_PERIOD,out rem); if ((rem == 0)&&(span!=0)) { DeliveryDemand delivery = this.backOffice.GetDeliveryDemands(modelTime); if (delivery != null) { DeliveryDemand[] dlvr = new DeliveryDemand[1] { delivery }; // это мне было лень generator.modifyDeliveries() переписывать this.storage.AddDeliveryDemand(this.generator.ModifyDeliveries(dlvr).ElementAt(0)); } } ////////////////////////////////////////////////// int runtimeModifyDemandsSumTime = 0; int newDemandInd = 0; int modifyDemandInd = 0; int nextPlanElemEndTime = 0; int todayWorkTime = 0; PlanReportElement curPlanElem = new PlanReportElement(); try { if (this.storage.GetFirstPlanElement().DemandID != 0) { int prodId = this.storage.GetFirstPlanElement().ProductID; nextPlanElemEndTime = Params.Products[prodId].Time; bool canDo = this.storage.Materials.TakeAwayMaterialCluster(Params.Products[prodId].Materials); if (canDo == false) throw new Exception("Не достаточно материалов для производства товара"); /* for (int j = 1; j <= CParams.MATERIALS_NUMBER; j++) { //***int materialNum = CParams.m_products[this.storage.GetFirstPlanElement().m_iProductID].m_iMaterials[j - 1]; int materialNum = 0; //получает в materialNum количество материала № j нужное для производства продукта CParams.m_products[this.storage.GetFirstPlanElement().m_iProductID].m_materials.GetMaterial(j, out materialNum); if (materialNum > 0) { //***this.storage.DeleteMaterialNumber(j, materialNum); //удаление со склада от материала с номером j количества materialNum this.storage.m_materials.TakeAwayMaterial(j, materialNum); } } */ } else { nextPlanElemEndTime = Params.RetargetTimes[this.storage.GetFirstPlanElement().ProductID-1]; } curPlanElem.StartExecuteDate=modelTime; } catch { nextPlanElemEndTime = -1; } if (nextPlanElemEndTime != -1) todayWorkTime += nextPlanElemEndTime; bool endOfDayFlag = false; int k = 0; while (endOfDayFlag == false) { k++; int newDemandNextTime = -1; int modifyDemandNextTime = -1; int nextDeliveryDemandTime = this.storage.GetNextDeliveryDemandTime(modelTime); if (newDemandInd < newDemands.Length) { newDemandNextTime = (int)(newDemands[newDemandInd].GettingDate - modelTime).TotalMinutes; } if (modifyDemandInd < modifyDemandsTime.Length) { runtimeModifyDemandsSumTime = modifyDemandsTime.Take(modifyDemandInd).Sum() + modifyDemandsTime[modifyDemandInd]; modifyDemandNextTime = runtimeModifyDemandsSumTime -(int)(modelTime - workdayStartTime).TotalMinutes; } if ((nextPlanElemEndTime == -1) && (newDemandNextTime == -1) && (modifyDemandNextTime == -1) && (nextDeliveryDemandTime == -1)) endOfDayFlag = true; else { List<int> nextTimes = new List<int>(); if (nextPlanElemEndTime != -1) nextTimes.Add(nextPlanElemEndTime); if (newDemandNextTime != -1) nextTimes.Add(newDemandNextTime); if (modifyDemandNextTime != -1) nextTimes.Add(modifyDemandNextTime); if (nextDeliveryDemandTime != -1) nextTimes.Add(nextDeliveryDemandTime); modelTime = modelTime.AddMinutes(nextTimes.Min()); if (modelTime.Day != workdayStartTime.Day) break; setLabelText(label, "Модельное время: " + modelTime.ToString()); if (nextTimes.Min() == newDemandNextTime) { bool approved = backOffice.ApproveDemand(ref newDemands[newDemandInd]); if (approved == true) storage.AddAcceptedDemand(newDemands[newDemandInd]); else storage.AddDeclinedDemand(newDemands[newDemandInd]); newDemandInd++; } if (nextTimes.Min() == modifyDemandNextTime) { var notFinishedDemands = this.storage.GetNotFinishedDemands(); if (notFinishedDemands.Count() > 0) { Demand modifiedDemand = this.generator.ModifyDemand(notFinishedDemands.ToArray(), modelTime); Demand demand; this.storage.GetAcceptedDemand(modifiedDemand.ID, out demand); bool approved = backOffice.ApproveModifyDemand(modelTime, ref modifiedDemand, demand); if (approved == true) this.storage.ModifyDemand(modifiedDemand); this.storage.AddModifyStatistic(approved); } modifyDemandInd++; } if ((nextTimes.Min() != nextPlanElemEndTime) && (nextPlanElemEndTime != -1)) nextPlanElemEndTime = nextPlanElemEndTime - nextTimes.Min(); if (nextTimes.Min() == nextPlanElemEndTime) { PlanElement planElem = this.storage.GetFirstPlanElementAndDelete(); curPlanElem.PlanElement = planElem; curPlanElem.EndExecuteDate = modelTime; this.storage.AddPlanReportElement(curPlanElem); // backOffice.reportPlanElem(curPlanElem); отчёт в бекофис не надо if ((planElem.DemandID!=0)&&(this.storage.IsDemandDone(planElem.DemandID) == true)) this.storage.FinishDemand(planElem.DemandID, modelTime); curPlanElem = new PlanReportElement(); try { if (this.storage.GetFirstPlanElement().DemandID != 0) { int prodId = this.storage.GetFirstPlanElement().ProductID; nextPlanElemEndTime = Params.Products[prodId].Time; bool canDo = this.storage.Materials.TakeAwayMaterialCluster(Params.Products[prodId].Materials); if (canDo == false) throw new Exception("Не достаточно материалов для производства товара"); /* for (int j = 1; j <= CParams.MATERIALS_NUMBER; j++) { //***int materialNum = CParams.m_products[this.storage.GetFirstPlanElement().m_iProductID + 1].m_iMaterials[j - 1]; int materialNum = 0; //получает в materialNum количество материала № j нужное для производства продукта CParams.m_products[this.storage.GetFirstPlanElement().m_iProductID].m_materials.GetMaterial(j, out materialNum); if (materialNum > 0) { //***this.storage.DeleteMaterialNumber(j, materialNum); //удаление со склада от материала с номером j количества materialNum this.storage.m_materials.TakeAwayMaterial(j, materialNum); } } */ } else { nextPlanElemEndTime = Params.RetargetTimes[this.storage.GetFirstPlanElement().ProductID-1]; } curPlanElem.StartExecuteDate = modelTime; } catch { nextPlanElemEndTime = -1; } if (nextPlanElemEndTime != -1) todayWorkTime += nextPlanElemEndTime; if (nextPlanElemEndTime != -1) // костыль для реализации круглосуточной работы { TimeSpan nextPlanElemEndTimeSpan = new TimeSpan(0,nextPlanElemEndTime,0); DateTime nextWorkDayStartTime = workdayStartTime + new TimeSpan(1,0,0,0); if (modelTime + nextPlanElemEndTimeSpan > nextWorkDayStartTime) { nextPlanElemEndTime = (int)(nextWorkDayStartTime - modelTime).TotalMinutes - this.storage.GetPlanElementsToGo(); } } } if (nextTimes.Min() == nextDeliveryDemandTime) { DeliveryDemand[] deliveryDemands = this.storage.GetDeliveryDemand(modelTime); if (deliveryDemands.Length > 0) { foreach (DeliveryDemand d in deliveryDemands) { this.storage.Materials.AddMaterialCluster(d.MaterialsDemand); /* for (int j = 1; j <= CParams.MATERIALS_NUMBER; j++) { //***int materialNum = d.m_materialsDemand[j]; int materialNum = 0; d.m_materialsDemand.GetMaterial(j, out materialNum); //if (materialNum > 0) //{ //***this.storage.AddMaterialNumber(j, materialNum); //добавление на склад количества materialNum материала номером j this.storage.m_materials.AddMaterial(j, materialNum); //} } */ backOffice.ReportDeliveryDemand(d); d.IsDone = true; } } } //// Не нужно если план не меняется в течение дня //if (nextPlanElemEndTime == -1) //{ // curPlanElem = new CPlanReportElement(); // try // { // int prodId = this.storage.GetFirstPlanElement().m_iProductID; // nextPlanElemEndTime = CParams.m_products[prodId].m_iTime; // this.storage.m_materials.TakeAwayMaterialCluster(CParams.m_products[prodId].m_materials); // /* // for (int j = 1; j <= CParams.MATERIALS_NUMBER; j++) // { // //***int materialNum = CParams.m_products[this.storage.GetFirstPlanElement().m_iProductID + 1].m_iMaterials[j - 1]; // int materialNum = 0; // //получает в materialNum количество материала № j нужное для производства продукта // CParams.m_products[this.storage.GetFirstPlanElement().m_iProductID].m_materials.GetMaterial(j, out materialNum); // if (materialNum > 0) // { // //***this.storage.DeleteMaterialNumber(j, materialNum); // //удаление со склада от материала с номером j количества materialNum // this.storage.m_materials.TakeAwayMaterial(j, materialNum); // } // } // */ // curPlanElem.m_dtStartExecute = modelTime; // } // catch // { // nextPlanElemEndTime = -1; // } //} } } //this.storage.SaveIdleStatistic((double)(CParams.WORKDAY_MINUTES_NUMBER - todayWorkTime) / CParams.WORKDAY_MINUTES_NUMBER); this.storage.SaveDemandAverageDelayStatistic(); this.storage.SaveFinishedDemandsPerDayStatistic(); this.storage.SaveCanceledDemandsPerDayStatistic(); } if (stopFlag!=true) setLabelText(label, "Модельное время: " + modelTime.ToString() + "\nМоделирование завершено"); return; }
/* public CDeliveryDemand[] GetNewDeliveryDemandsAndDelete() // получить все новые заявки на поставку материалов и удалить их { List<CDeliveryDemand> list = new List<CDeliveryDemand>(); for (int i=0; i < this.m_newDeliveryDemands.Count; i++) { list.Add(this.m_newDeliveryDemands.Dequeue()); } this.m_newDeliveryDemands.Clear(); return list.ToArray(); } public bool AddNewDeliveryDemand(CDeliveryDemand deliveryDemand) //добавить новую заявку на поставку материалов { this.m_newDeliveryDemands.Enqueue(deliveryDemand); return true; } */ /// <summary> /// добавить обработанную заявку на поставку материалов /// </summary> /// <param name="deliveryDemand"></param> /// <returns></returns> public bool AddDeliveryDemand(DeliveryDemand deliveryDemand) { if (DeliveryDemands.ContainsKey(deliveryDemand.ID)) return ModelError.Error(); this.DeliveryDemands.Add(deliveryDemand.ID, deliveryDemand); return true; }