public override bool NextStep() { if (ProductionState.FutureProductionPlan.Count == 0) { return(false); } #if HISTORY History.Push(ProductionState.Copy()); #endif var needed = ProductionState.FutureProductionPlan.Dequeue(); var current = ProductionState.ProductionHistory.Dequeue(); ProductionState.ProductionHistory.Enqueue(needed); var nearestFreePosition = GetNearestEmptyPosition(ProductionState); (int r, int c) = ProductionState.GetWarehouseIndex(nearestFreePosition); ProductionState.WarehouseState[r, c] = current; var nearestNeededPosition = GetNearesElementWarehousePosition(ProductionState, needed); (r, c) = ProductionState.GetWarehouseIndex(nearestNeededPosition); ProductionState.WarehouseState[r, c] = ItemState.Empty; var insertTime = ProductionState.TimeMatrix[ProductionState.GetTimeMatrixIndex(PositionCodes.Stacker), ProductionState.GetTimeMatrixIndex(nearestFreePosition)]; var moveToDifferentCellTime = ProductionState.TimeMatrix[ProductionState.GetTimeMatrixIndex(nearestFreePosition), ProductionState.GetTimeMatrixIndex(nearestNeededPosition)] - 5; // TODO: Validate this calculation moveToDifferentCellTime = moveToDifferentCellTime < 0 ? 0 : moveToDifferentCellTime; var withdrawTime = ProductionState.TimeMatrix[ProductionState.GetTimeMatrixIndex(nearestNeededPosition), ProductionState.GetTimeMatrixIndex(PositionCodes.Stacker)]; var totalTime = insertTime + moveToDifferentCellTime + withdrawTime; ProductionState.CurrentStepTime = totalTime; ProductionState.TimeSpentInSimulation += totalTime; ProductionState.ProductionStateIsOk = ProductionState.ProductionStateIsOk && totalTime <= TimeLimit; RealTime += ClockTime; if (totalTime > TimeLimit) { Delay += totalTime - TimeLimit; RealTime += totalTime - TimeLimit; } ProductionState.StepCounter++; StepLog.Add(new StepModel { InsertToCell = nearestFreePosition, WithdrawFromCell = nearestNeededPosition, InsertType = current, WithdrawType = needed, InsertTime = insertTime, MoveToDifferentCellTime = moveToDifferentCellTime, WithdrawTime = withdrawTime }); return(true); }
public override void GetHandler() { var nearestNeededPosition = GetNearesElementWarehousePosition(ProductionState, ItemState.Empty); var stackerRoundtripForItem = ProductionState[PositionCodes.Stacker, nearestNeededPosition] + ProductionState[nearestNeededPosition, PositionCodes.Stacker] - StackerOperationTime * 2; ProductionState[nearestNeededPosition] = Current; var nextIntake = GetClosestNextIntakeTime(); var realTimeBeforeOp = RealTime; RealTime += stackerRoundtripForItem; IsReadyForBreak = true; AsyncStepModel step = new AsyncStepModel { CurrentState = AsyncControllerState.Get, Message = $"RealTime: {RealTime}, Current: {Current}, Took item to position: {nearestNeededPosition} with time {stackerRoundtripForItem}, Next intake in: {nextIntake}, Time before get: {realTimeBeforeOp}" }; /*if (RealTime > nextIntake) * { * Delay += RealTime - nextIntake; * nextIntake = GetClosestNextIntakeTime(); * }*/ ProductionState.ProductionHistory.Dequeue(); if (ProductionState.FutureProductionPlan.Peek() == ProductionState.ProductionHistory.Peek()) { CurrentState = AsyncControllerState.Start; RealTime = nextIntake; IntakeItem = ItemState.Empty; step.Message += $", Going to state: {CurrentState}, Skipped to intake {nextIntake}"; StepLog.Add(step); return; } double closestOuttake = GetClosestNextOuttakeTime(); double previousOuttake = GetPreviousOuttakeTime(); if (RealTime < closestOuttake && RealTime < previousOuttake) { RealTime = closestOuttake; step.Message += $", Skipped to outtake: {RealTime}"; } CurrentState = AsyncControllerState.Put; PreviousStateForPut = AsyncControllerState.Get; Needed = ProductionState.FutureProductionPlan.Peek(); step.Message += $", Going to state: {CurrentState}"; StepLog.Add(step); }
public override void PutHandler() { var nearestNeededPosition = GetNearesElementWarehousePosition(ProductionState, Needed); var stackerRoundtripForItem = ProductionState[PositionCodes.Stacker, nearestNeededPosition] + ProductionState[nearestNeededPosition, PositionCodes.Stacker] - StackerOperationTime * 2; ProductionState[nearestNeededPosition] = ItemState.Empty; var realTimeBeforeOp = RealTime; var nextOuttake = GetClosestNextOuttakeTime(); var nextIntake = GetClosestNextIntakeTime(); RealTime += stackerRoundtripForItem; Current = ProductionState.ProductionHistory.Peek(); IsReadyForBreak = false; AsyncStepModel step = new AsyncStepModel { CurrentState = AsyncControllerState.Put, Message = $"RealTime: {RealTime}, Need: {Needed}, Took item from position: {nearestNeededPosition} with time {stackerRoundtripForItem}, Next outtake in: {nextOuttake}, Came here from: {PreviousStateForPut}, Time before put: {realTimeBeforeOp}" }; switch (PreviousStateForPut) { case AsyncControllerState.Start: if (RealTime > nextOuttake) { Delay += RealTime - nextOuttake; CurrentState = AsyncControllerState.Get; nextOuttake = GetClosestNextOuttakeTime(); } if (RealTime <= nextOuttake) { OuttakeItem = Needed; CurrentState = AsyncControllerState.Get; //double closestIntake = GetClosestNextIntakeTime(); double closestIntake = nextIntake; if (RealTime < closestIntake) { RealTime = closestIntake; step.Message += $", Skipped to intake: {RealTime}"; } } break; //TODO: 7205 ma byt 131 tzn 1309 je zbytek //TODO: 2750 ma byt 50 aut a 1390 zbyva case AsyncControllerState.SwapChain: var deq = ProductionState.FutureProductionPlan.Dequeue(); ProductionState.ProductionHistory.Enqueue(deq); CurrentState = AsyncControllerState.Get; if (RealTime <= nextIntake) { //RealTime = GetClosestNextIntakeTime(); RealTime = nextIntake; step.Message += $", Skipped to intake: {RealTime}"; } OuttakeItem = Needed; Current = ProductionState.ProductionHistory.Peek(); IntakeItem = Current; break; case AsyncControllerState.Get: if (RealTime > nextOuttake) { Delay += RealTime - nextOuttake; CurrentState = AsyncControllerState.Get; nextOuttake = GetClosestNextOuttakeTime(); } if (RealTime <= nextOuttake) { OuttakeItem = Needed; Current = ProductionState.ProductionHistory.Peek(); CurrentState = AsyncControllerState.Get; var deq1 = ProductionState.FutureProductionPlan.Dequeue(); ProductionState.ProductionHistory.Enqueue(deq1); double closestIntake = GetClosestNextIntakeTime(); double previousIntake = GetPreviousOuttakeTime() - IntakeOuttakeDifference; if (RealTime < closestIntake & RealTime < previousIntake) { RealTime = closestIntake; step.Message += $", Skipped to intake: {RealTime}"; } } break; } step.Message += $", Going to state: {CurrentState}"; StepLog.Add(step); }