public void AddToQueue(DetailPos dp, FMM currentModule) { if (dp.Index != 15) { float time = dp.StartTime; DetailPos last = DetailQueue.LastOrDefault() ?? new DetailPos { Index = -1, Duration = 0, StartTime = 0 }; dp.StartTime = Math.Max(EndTime, currentModule.CurrentDetail.CurrentEndTime - currentModule.CurrentDetail.CurrentDuration); float idleDuration = dp.StartTime - (last.StartTime + last.Duration); if (idleDuration > 0.01) { DetailPos idle = new DetailPos { Index = 0, StartTime = last.StartTime + last.Duration, Duration = idleDuration }; DetailQueue.Add(idle); } DetailQueue.Add(dp); currentModule.CurrentDetail.CurrentEndTime += dp.Duration + EndTime - (time - currentModule.CurrentDetail.CurrentDuration); EndTime = currentModule.CurrentDetail.CurrentEndTime - currentModule.CurrentDetail.CurrentDuration + idleDuration; } else { DetailQueue.Add(dp); EndTime += dp.Duration; } }
public void Resolve() { FMM currentModule = null; for (int i = 0; i < DetailsCount; i++) { Details[i].CurrentModule.Bag.Add(Details[i]); } do { float currentTime = float.MaxValue; foreach (var module in Modules) { if (module.Bag.Any()) { if (module.CurrentDetail == null) { module.SetDetail(); } if (module.CurrentDetail != null) { if (module.CurrentDetail.CurrentEndTime <= currentTime) { currentTime = module.CurrentDetail.CurrentEndTime; currentModule = module; } } } } if (currentModule == null || currentModule.CurrentDetail == null) { break; } currentModule.CurrentDetail.StartTimes[currentModule.CurrentDetail.OpNumber] = currentTime - currentModule .CurrentDetail .CurrentDuration; currentModule.AddToQueue(); currentModule.CurrentDetail.RemoveFromBag(); currentModule.CurrentDetail.ToNextOperation(); currentModule.CurrentDetail = null; } while (true); TotalTime = 0; foreach (var module in Modules) { var lastDetail = module.DetailQueue.LastOrDefault(); if (lastDetail != null) { var moduleFinishTime = lastDetail.StartTime + lastDetail.Duration; if (moduleFinishTime > TotalTime) { TotalTime = moduleFinishTime; } } } }
public void SetDetail(FMM module) { module.CurrentDetail = (from detail in module.Bag where detail.CurrentDuration == module.Bag.Max(d => d.CurrentDuration) select detail) .FirstOrDefault(); }
public void SetDetail(FMM module) { float minTime = float.MaxValue; Detail chosen = null; foreach (var detail in module.Bag) { int index = detail.OpNumber + 1; float time = index < detail.Route.Length ? detail.Route[index].Bag.Sum(d => d.CurrentDuration) : float.MaxValue; if (time <= minTime) { minTime = time; chosen = detail; } } module.CurrentDetail = chosen; }
public void SetDetail(FMM module) { float minRestTime = float.MaxValue; Detail chosen = null; foreach (var detail in module.Bag) { float restTime = 0; for (int i = detail.OpNumber; i < detail.Durations.Length; i++) { restTime += detail.Durations[i]; } if (restTime <= minRestTime) { minRestTime = restTime; chosen = detail; } } module.CurrentDetail = chosen; }
public void SetDetail(FMM module) { module.CurrentDetail = module.Bag.Last(); }
public float ResolveTransport(FMM module, float time, out float transportTime) { bool linearFlag = false; int to = module.Index, @from = module.CurrentDetail.OpNumber == 0 ? 0 : module.CurrentDetail.Route[module.CurrentDetail.OpNumber - 1].Index; int routeLength = TransportLengths[@from, to]; if (to == 6 || to == 5) { linearFlag = true; } if (to == 4 || to == 3) { linearFlag = true; } transportTime = Tpid * routeLength + Tpost; if (to == 0) { transportTime += Tpost; } else { transportTime += Tz; } if (linearFlag) { transportTime += Tvz + Tpost; } if (@from == 0) { transportTime += Tvz; } else { transportTime += Tr; } DetailPos current, idle, linearPos, linearIdle; switch (to) { case 3: current = new DetailPos { Index = module.CurrentDetail.Index, StartTime = time, Duration = transportTime - Tvz - Tz }; //module.CurrentDetail.StartTimes[module.CurrentDetail.OpNumber] += transportTime; Atm1.AddToQueue(current, module); idle = new DetailPos { Index = 15, StartTime = current.StartTime + current.Duration, Duration = Tpid * routeLength }; Atm1.AddToQueue(idle, module); linearPos = new DetailPos { Index = module.CurrentDetail.Index, StartTime = current.StartTime + current.Duration, Duration = Tvz + Tz }; Atm2.AddToQueue(linearPos, module); break; case 4: current = new DetailPos { Index = module.CurrentDetail.Index, StartTime = time, Duration = transportTime - Tvz - Tz }; //module.CurrentDetail.StartTimes[module.CurrentDetail.OpNumber] += transportTime; Atm1.AddToQueue(current, module); idle = new DetailPos { Index = 15, StartTime = current.StartTime + current.Duration, Duration = Tpid * routeLength }; Atm1.AddToQueue(idle, module); linearPos = new DetailPos { Index = module.CurrentDetail.Index, StartTime = current.StartTime + current.Duration, Duration = Tvz + Tz }; Atm3.AddToQueue(linearPos, module); break; case 5: current = new DetailPos { Index = module.CurrentDetail.Index, StartTime = time, Duration = transportTime - Tvz - Tz - Tpid }; //module.CurrentDetail.StartTimes[module.CurrentDetail.OpNumber] += transportTime - Tvz - Tz - Tpid; Atm1.AddToQueue(current, module); idle = new DetailPos { Index = 15, StartTime = current.StartTime + current.Duration, Duration = Tpid * (routeLength - 1) }; Atm1.AddToQueue(idle, module); linearPos = new DetailPos { Index = module.CurrentDetail.Index, StartTime = current.StartTime + current.Duration, Duration = Tvz + Tz + Tpid }; Atm3.AddToQueue(linearPos, module); linearIdle = new DetailPos { Index = 15, StartTime = linearPos.StartTime + linearPos.Duration, Duration = Tpid }; Atm3.AddToQueue(linearIdle, module); break; case 6: current = new DetailPos { Index = module.CurrentDetail.Index, StartTime = time, Duration = transportTime - Tvz - Tz - Tpid }; //module.CurrentDetail.StartTimes[module.CurrentDetail.OpNumber] += transportTime - Tvz - Tz - Tpid; Atm1.AddToQueue(current, module); idle = new DetailPos { Index = 15, StartTime = current.StartTime + current.Duration, Duration = Tpid * (routeLength - 1) }; Atm1.AddToQueue(idle, module); linearPos = new DetailPos { Index = module.CurrentDetail.Index, StartTime = current.StartTime + current.Duration, Duration = Tvz + Tz + Tpid }; Atm2.AddToQueue(linearPos, module); linearIdle = new DetailPos { Index = 15, StartTime = linearPos.StartTime + linearPos.Duration, Duration = Tpid }; Atm2.AddToQueue(linearIdle, module); break; case 0: break; default: current = new DetailPos { Index = module.CurrentDetail.Index, StartTime = time, Duration = transportTime }; //module.CurrentDetail.StartTimes[module.CurrentDetail.OpNumber] += transportTime - Tvz - Tz - Tpid; Atm1.AddToQueue(current, module); idle = new DetailPos { Index = 15, StartTime = current.StartTime + current.Duration, Duration = Tpid * routeLength }; Atm1.AddToQueue(idle, module); break; } return(module.CurrentDetail.CurrentEndTime - module.CurrentDetail.CurrentDuration); }
public void ReadDataFromTxt(string path) { string[] lines = File.ReadAllLines(path); EquipmentCount = int.Parse(lines[0]); DetailsCount = int.Parse(lines[1]); int ruleNumber = int.Parse(lines[2]); switch (ruleNumber) { case 1: RuleHandler = new ShortestOpHandler(); break; case 2: RuleHandler = new MaxRestComplexityHandler(); break; case 3: RuleHandler = new SmoothLoadHandler(); break; case 4: RuleHandler = new MinRestComplexityHandler(); break; case 5: RuleHandler = new LongestOpHandler(); break; case 6: RuleHandler = new FIFOHandler(); break; case 7: RuleHandler = new LIFOHandler(); break; } Modules = new FMM[EquipmentCount]; for (int i = 0; i < EquipmentCount; i++) { Modules[i] = new FMM(); Modules[i].Index = i + 1; Modules[i].Bag = new List <Detail>(); Modules[i].DetailQueue = new List <DetailPos>(); Modules[i].RuleHandler = RuleHandler; } Details = new Detail[DetailsCount]; for (int i = 0; i < DetailsCount; i++) { Details[i] = new Detail(); Details[i].Index = i + 1; string[] routeString = lines[i + 3].Split(new[] { ' ' }); int routeLength = routeString.Length; string[] durationString = lines[i + 4 + DetailsCount].Split(new[] { ' ' }, routeLength); Details[i].Route = new FMM[routeLength]; Details[i].Durations = new float[routeLength]; Details[i].StartTimes = new float[routeLength]; for (int j = 0; j < routeLength; j++) { Details[i].Route[j] = Modules[int.Parse(routeString[j].Trim()) - 1]; Details[i].Durations[j] = float.Parse(durationString[j].Trim()); } } TransportLengths = new int[EquipmentCount + 1, EquipmentCount + 1]; for (int i = 0; i < EquipmentCount + 1; i++) { string[] routeString = lines[i + 5 + 2 * DetailsCount].Split(new[] { ' ' }); int routeLength = routeString.Length; for (int j = 0; j < routeLength; j++) { string elem = routeString[j].Trim(); TransportLengths[i, j] = elem == "-" ? -1 : int.Parse(elem); } } Tvz = float.Parse(lines[6 + 2 * DetailsCount + EquipmentCount]); Tpost = float.Parse(lines[7 + 2 * DetailsCount + EquipmentCount]); Tz = float.Parse(lines[8 + 2 * DetailsCount + EquipmentCount]); Tr = float.Parse(lines[9 + 2 * DetailsCount + EquipmentCount]); Tpid = float.Parse(lines[10 + 2 * DetailsCount + EquipmentCount]); }