public InsertDevice(Configuration Conf, int ItemId, BaseDeviceType DevType) { InitializeComponent(); conf = Conf; devType = DevType; itemId = ItemId; this.Text = devType == BaseDeviceType.Saw ? "Изменить конфигурацию пилы" : "Изменить конфигурацию шлифовального станка"; DeviceList GoalList = devType == BaseDeviceType.Saw ? conf.Saws : conf.Grinders; int DeviceIndex = GoalList.GetIndexById(itemId); textBox1.Text = GoalList[DeviceIndex].Text; textBox2.Text = GoalList[DeviceIndex].Responsible; textBox4.Text = GoalList[DeviceIndex].ServiceTimePeriod.ToString(); textBox5.Text = GoalList[DeviceIndex].ServiceTime.ToString(); DefaultMaterialId = GoalList[DeviceIndex].DefaultMaterialId; for (int i = 0; i < GoalList[DeviceIndex].SupportedMaterials.Count; i++) { mpl.Add((MaterialPair)GoalList[DeviceIndex].SupportedMaterials[i].Clone()); } LoadMaterials(); LoadSupMaterials(); }
/// <summary> /// Возвращает самое длинное задание с заданным материалом. /// </summary> /// <param name="MaterialId"></param> /// <param name="Products"></param> /// <param name="Device"></param> /// <returns></returns> public int GetBiggerTask(int MaterialId, MaterialList Materials, ProductionList Products, BaseDeviceType Device) { int TaskIndex = -1; double TaskTime = 0; for (int i = 0, i_end = this.Count; i < i_end; i++) { if (this[i].MaterialId == MaterialId) { if (TaskIndex == -1) { TaskIndex = i; TaskTime = (Device == BaseDeviceType.Saw ? this[i].SawingTime(Materials, Products) : this[i].PolishingTime(Materials, Products)); } else { double NewTime = (Device == BaseDeviceType.Saw ? this[i].SawingTime(Materials, Products) : this[i].PolishingTime(Materials, Products)); if (NewTime > TaskTime) { TaskIndex = i; TaskTime = NewTime; } } } } return TaskIndex != -1 ? this[TaskIndex].Id : -1; }
public InsertDevice(Configuration Conf, BaseDeviceType DevType) { InitializeComponent(); conf = Conf; devType = DevType; if (devType == BaseDeviceType.Saw) { this.Text = "Добавить новую пилу"; } this.Text = devType == BaseDeviceType.Saw ? "Добавить новую пилу" : "Добавить шлифовальный станок"; LoadMaterials(); }
/// <summary> /// Возвращает суммарную длительность заданий, /// состоящих из одного материала /// </summary> /// <param name="MaterialId"></param> /// <param name="Products"></param> /// <param name="Device"></param> /// <returns></returns> public double TaskDurationByMaterial(int MaterialId, MaterialList Materials, ProductionList Products, BaseDeviceType Device) { double Result = 0; for (int i = 0, i_end = this.Count; i < i_end; i++) { if (this[i].MaterialId == MaterialId) { Result += Device == BaseDeviceType.Saw ? this[i].SawingTime(Materials, Products) : this[i].PolishingTime(Materials, Products); } } return Result; }
/// <summary> /// Возвращает идентификатор наиболее важного задания. /// Важность зависит от времени выполнения. /// Чем дольше задание выполняется, тем оно важнее. /// </summary> /// <param name="DefaultList"></param> /// <param name="MaterialID"></param> /// <returns></returns> private int MostImportantTask(TaskList Tasks, MaterialList Materials, ProductionList Productions, int MaterialID, BaseDeviceType DeviceType) { int ResultId = -1; if (Tasks.Count == 0) return ResultId; // находим индекс первого задания данного типа int ResultIndex = -1; for (int i = 0; i < Tasks.Count; i++) { if (Tasks[i].MaterialId == MaterialID) { ResultIndex = i; break; } } // если заданий под нужный материал вовсе нет, то до свидания if (ResultIndex == -1) return ResultId; ResultId = Tasks[ResultIndex].Id; for (int i = ResultIndex + 1; i < Tasks.Count; i++) { if (Tasks[i].MaterialId != MaterialID) continue; if ((DeviceType == BaseDeviceType.Saw ? Tasks[i].SawingTime(Materials, Productions) : Tasks[i].PolishingTime(Materials, Productions)) > (DeviceType == BaseDeviceType.Saw ? Tasks[ResultIndex].SawingTime(Materials, Productions) : Tasks[ResultIndex].PolishingTime(Materials, Productions))) { ResultId = Tasks[i].Id; ResultIndex = i; } } return ResultId; }
/// <summary> /// Метод возвращает идентификатор материала которого больше всего /// по времени обработки на пиле. /// </summary> /// <param name="DefaultSawingList"></param> private int MostImportantMaterial(TaskList Tasks, MaterialList Materials, ProductionList Productions, BaseDeviceType DeviceType) { // список в котором хранится материал и суммарное время всех заданий // под данный материал List<MaterialPair> material = new List<MaterialPair>(); // перебираем задания и наполняем список времен for (int i = 0; i < Tasks.Count; i++) { int CurrentMaterialID = Tasks[i].MaterialId; int FindedMaterialIndex = -1; for (int j = 0; j < material.Count; j++) { if (material[j].ID == CurrentMaterialID) { FindedMaterialIndex = j; break; } } // если материал уже есть в списке if (FindedMaterialIndex > -1) material[FindedMaterialIndex].Time += DeviceType == BaseDeviceType.Saw ? Tasks[i].SawingTime(Materials, Productions) : Tasks[i].PolishingTime(Materials, Productions); else // если материала нет в списке material.Add(new MaterialPair(CurrentMaterialID, DeviceType == BaseDeviceType.Saw ? Tasks[i].SawingTime(Materials, Productions) : Tasks[i].PolishingTime(Materials, Productions))); } // перебираем задания и наполняем список времен int Result = -1; double CurrentMaxTime = 0; for (int i = 0; i < material.Count; i++) { if (material[i].Time > CurrentMaxTime) { CurrentMaxTime = material[i].Time; Result = i; } } return Result != -1 ? material[Result].ID : -1; }
/// <summary> /// Возвращает устройство - альтернативу DeviceId, то есть такое устройство /// которое способно обработать MaterialId и которое освободится в ближайшее время или уже свободное. /// </summary> /// <param name="MaterialId"></param> /// <param name="DeviceId"></param> /// <param name="Device"></param> /// <returns></returns> public int GetBestAlternative(int MaterialId, int DeviceId, BaseDeviceType Device) { int BestIndex = -1; for (int i = 0, i_end = this.Count; i < i_end; i++) { if (this[i].Id != DeviceId) { if (this[i].IsSupportMaterial(MaterialId)) { if (BestIndex == -1) { BestIndex = i; } else { if (this[i].Time < this[BestIndex].Time) { BestIndex = i; } } } } } return this[BestIndex].Id; }