void partArrive(Machine machine, int part_i) //部件上机事件 { double time = currentEvent.occur_time; foreach (Part part in machine.onholdParts) { Part currentPart = part; Part lastPart; //换模时间的判定 if (machine.status == MachineStatus.Vergin) { lastPart = currentPart; } else { lastPart = parts[machine.last_part]; } machine.last_part = part.part_No; machine.setBusy(); time += TimeCompute(machine, currentPart, lastPart); //生成当前部件在当前机器的下机事件 P_Event down_Event = new P_Event(time, -1, machine.Machine_No, currentPart.part_No); addEvent(events, down_Event); machine.finished_Time = time; leaveTimes[part.part_Type, machine.Machine_Type] += time; } machines[machine.Machine_No].onholdParts = new ArrayList(); }
void run() { init(); while (events.Count != 0) { currentEvent = (P_Event)events[0]; if (currentEvent.EventType == 1) //事件类型为1,上机事件 { partArrive(machines[currentEvent.machine], currentEvent.part_i); } else { partLeave(machines[currentEvent.machine], currentEvent.part_i); } events.RemoveAt(0); } end(); }
void addEvent(ArrayList list, P_Event @event) //事件添加函数,会按照事件发生事件排序 { if (@event.occur_time >= ((P_Event)list[list.Count - 1]).occur_time) { list.Add(@event); } else { for (int i = 0; i != list.Count; i++) { if (((P_Event)list[i]).occur_time > @event.occur_time) { list.Insert(i, @event); break; } } } }