Exemplo n.º 1
0
        /// <summary>
        ///  Simulate the process. 
        /// </summary>
        public override IEnumerator<InstructionBase> Simulate()
        {
            var inventory = Context.GetByType<WarehouseInventory>().First();

            long waitStart = Context.TimePeriod;

            while(_orderQueue.Count >0)
            {
                if (Context.TimePeriod > waitStart){
                    WaitTime += (Context.TimePeriod - waitStart);
                    waitStart = Context.TimePeriod;
                }

                Order orderToDeliver = null;

                int i = 0;
                while(i < _orderQueue.Count && orderToDeliver == null){
                    var orderToCheck = _orderQueue.Dequeue();
                    if (inventory.CanRemove(orderToCheck.Product, orderToCheck.Quantity)){
                        orderToDeliver = orderToCheck;
                    }
                    else{
                        // the order can't be filled yet.. push it to the end of the queue
                        _orderQueue.Enqueue(orderToCheck);
                    }
                    i++;
                }

                if (orderToDeliver == null){
                    // can't deliver anything now... pass
                    yield return new PassInstruction();
                }
                else {
                    // remove from the warehouse
                    inventory.Remove(orderToDeliver.Product, orderToDeliver.Quantity);

                    // check the remaining quantity
                    int quantity = inventory.CheckQuantity(orderToDeliver.Product);

                    if (quantity <= orderToDeliver.Product.ReorderCount
                        && (quantity + orderToDeliver.Quantity) > orderToDeliver.Product.ReorderCount){
                        // the recent removal pushed levels below the reorder count
                        // start the reorder process
                        var reorder = new ReorderProcess(orderToDeliver.Product);
                        yield return new ActivateInstruction(reorder);
                    }
                    // deliver the order
                    // work out how far to travel
                    int distanceToTravel = (int)Math.Sqrt((orderToDeliver.DeliveryAddress.X * orderToDeliver.DeliveryAddress.X)
                                                     + (orderToDeliver.DeliveryAddress.Y * orderToDeliver.DeliveryAddress.Y));

                    // include travel back to warehouse
                    distanceToTravel = distanceToTravel * 2;

                    int timeToTravel = (int)(distanceToTravel / 10);

                    var deliveryStartTime = Context.TimePeriod;
                    // wait the delivery time
                    yield return new WaitInstruction(timeToTravel);
                    var deliveryEndTime = Context.TimePeriod;

                    BusyTime += (deliveryEndTime - deliveryStartTime);
                    DeliveryCount++;
                    waitStart = Context.TimePeriod;
                    LatestDeliveryTime = Context.TimePeriod;
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///  Simulate the process.
        /// </summary>
        public override IEnumerator <InstructionBase> Simulate()
        {
            WarehouseInventory inventory = Context.GetByType <WarehouseInventory>().First();

            var waitStart = Context.TimePeriod;

            while (_orderQueue.Count > 0)
            {
                if (Context.TimePeriod > waitStart)
                {
                    WaitTime += (Context.TimePeriod - waitStart);
                    waitStart = Context.TimePeriod;
                }

                Order orderToDeliver = null;

                var i = 0;
                while (i < _orderQueue.Count && orderToDeliver == null)
                {
                    Order orderToCheck = _orderQueue.Dequeue();
                    if (inventory.CanRemove(orderToCheck.Product, orderToCheck.Quantity))
                    {
                        orderToDeliver = orderToCheck;
                    }
                    else
                    {
                        // the order can't be filled yet.. push it to the end of the queue
                        _orderQueue.Enqueue(orderToCheck);
                    }
                    i++;
                }

                if (orderToDeliver == null)
                {
                    // can't deliver anything now... pass
                    yield return(new PassInstruction());
                }
                else
                {
                    // remove from the warehouse
                    inventory.Remove(orderToDeliver.Product, orderToDeliver.Quantity);

                    // check the remaining quantity
                    var quantity = inventory.CheckQuantity(orderToDeliver.Product);

                    if (quantity <= orderToDeliver.Product.ReorderCount &&
                        (quantity + orderToDeliver.Quantity) > orderToDeliver.Product.ReorderCount)
                    {
                        // the recent removal pushed levels below the reorder count
                        // start the reorder process
                        var reorder = new ReorderProcess(Context, orderToDeliver.Product);
                        yield return(new ActivateInstruction(reorder));
                    }
                    // deliver the order
                    // work out how far to travel
                    var distanceToTravel = (int)Math.Sqrt((orderToDeliver.DeliveryAddress.X * orderToDeliver.DeliveryAddress.X)
                                                          + (orderToDeliver.DeliveryAddress.Y * orderToDeliver.DeliveryAddress.Y));

                    // include travel back to warehouse
                    distanceToTravel = distanceToTravel * 2;

                    var timeToTravel = distanceToTravel / 10;

                    var deliveryStartTime = Context.TimePeriod;
                    // wait the delivery time
                    yield return(new WaitInstruction(timeToTravel));

                    var deliveryEndTime = Context.TimePeriod;

                    BusyTime += (deliveryEndTime - deliveryStartTime);
                    DeliveryCount++;
                    waitStart          = Context.TimePeriod;
                    LatestDeliveryTime = Context.TimePeriod;
                }
            }
        }