Exemple #1
0
        public override void GenerateAction(int sec)
        {
            if (sec == 0)
            {
                _actionString = (_id - 5).ToString(); // Trick: Because we set id = {6 7 8 9} to avoid 0 and 1
            }

            if (_shippingTime < 4)
            {
                if (_shippingTime == 0)
                {
                    if (sec + 5 > 59)
                    {
                        _actionString += " n";
                        return;
                    }

                    transporter = GetAdjacentTransporter(); // Find a transporter
                    if (transporter == null)
                    {
                        _actionString += " n"; // Can't find transporter, return
                        return;
                    }

                    _actionString            = _actionString + " s " + transporter._id + " " + transporter._loadedItems.Peek();
                    transporter._isUnloading = true;
                }
                _shippingTime++;
            }
            else
            {
                transporter.FinishShipping();
                _shippingTime = 0;
            }
        }
Exemple #2
0
        public override void GenerateAction(int sec)
        {
            if (sec == 0)
            {
                _actionString = "0";
            }

            if (_receivingTime < 4)
            {
                if (_receivingTime == 0)
                {
                    if (sec + 5 > 59)
                    {
                        _actionString += " n";
                        return;
                    }

                    transporter = GetAdjacentTransporter(); // Find a transporter
                    if (transporter == null)
                    {
                        _actionString += " n"; // Can't find transporter, return
                        return;
                    }

                    _actionString          = _actionString + " p " + transporter._id + " " + transporter._expectedReceiveItems.Peek();
                    transporter._isLoading = true;
                }
                _receivingTime++;
            }
            else
            {
                transporter.FinishReceiving();
                _receivingTime = 0;
            }
        }
Exemple #3
0
        protected TransportRobot GetAdjacentTransporter()
        {
            int x = _location.X;
            int y = _location.Y;

            var proposedLocations = new List <Point>()
            {
                new Point(x - 1, y),
                new Point(x + 1, y),
                new Point(x, y - 1),
                new Point(x, y + 1),
            };

            foreach (Point location in proposedLocations)
            {
                Byte id = Warehouse.ValueAt(location);
                if (id > 9 && Warehouse._Transporters.ContainsKey(id))
                {
                    TransportRobot robot = (TransportRobot)Warehouse._Transporters[id];
                    if (robot._path.Count == 0 && robot._destination_point.Equals(_destination_point))
                    {
                        return(robot);
                    }
                }
            }

            return(null);
        }
Exemple #4
0
        public void Slot(List <string> input)
        {
            for (int i = 1; i < input.Count; i += 2) // Add new order into the list
            {
                Order new_order      = new Order(input[i], int.Parse(input[i + 1]));
                Order existing_order = _SlotOrders.FirstOrDefault(x => x._productID.Equals(new_order._productID));
                if (existing_order != null)
                {
                    existing_order._quantity += new_order._quantity;
                }
                else
                {
                    _SlotOrders.Add(new_order);
                }
            }

            //// Need to remove here
            //if (_time == 0 && _day != 0) // resume the activity of previous day
            //{
            //    foreach (Robot robot in _AllMovingRobots.Values)
            //    {
            //        robot.ResumeActivityLastDay();
            //    }
            //}

            if (_time < 714)
            {
                while (_SlotOrders.Count > 0)
                {
                    TransportRobot transporter = FindTransporterToSlot(_Receiver._location);
                    if (transporter == null) // All transporters are busy
                    {
                        return;
                    }

                    while (transporter._expectedReceiveItems.Count < TransportRobot._maxItem)
                    {
                        Order order = FindNextSlotOrder(transporter);
                        if (order == null)
                        {
                            break;
                        }
                        transporter.UpdateExpectedReceiveItem(order);
                        if (order._quantity == 0)
                        {
                            _SlotOrders.Remove(order);
                        }
                    }

                    transporter.PrepareToReceive();
                }
            }
            else
            {
                foreach (Robot robot in _AllMovingRobots.Values)
                {
                    robot.ForceReturnChargingPoint();
                }
            }
        }
Exemple #5
0
        private TransportRobot GetAdjacentTransporter()
        {
            foreach (Point location in _shipPoints)
            {
                Byte id = Warehouse.ValueAt(location);
                if (id > 9 && Warehouse._Transporters.ContainsKey(id))
                {
                    TransportRobot robot = (TransportRobot)Warehouse._Transporters[id];
                    if (robot._state == robot_state.ship &&
                        robot._loadedItems.Count > 0 &&
                        robot._path.Count == 0)
                    {
                        return(robot);
                    }
                }
            }

            return(null);
        }
Exemple #6
0
        public Order FindNextSlotOrder(TransportRobot robot)
        {
            if (_SlotOrders.Count == 0)
            {
                return(null);
            }

            if (robot._expectedReceiveItems.Count == 0)
            {
                return(_SlotOrders[0]);
            }

            string  product_id      = robot._expectedReceiveItems.Peek();
            Product current_product = _DicItems[product_id];

            if (current_product._storageType.Equals("fold"))
            {
                foreach (Order order in _SlotOrders)
                {
                    Product another_product = _DicItems[order._productID];

                    if (another_product._storageType.Equals(current_product._storageType) &&
                        another_product._productType.Equals(current_product._productType) &&
                        another_product._shipperID == current_product._shipperID)
                    {
                        return(order);
                    }
                }
            }
            else
            {
                foreach (Order order in _SlotOrders)
                {
                    Product another_product = _DicItems[order._productID];
                    if (another_product._storageType.Equals(current_product._storageType) &&
                        another_product._shipperID == current_product._shipperID)
                    {
                        return(order);
                    }
                }
            }
            return(null);
        }
Exemple #7
0
        public static Order FindNextPickOrder(TransportRobot robot)
        {
            if (_PickOrders.Count == 0)
            {
                return(null);
            }

            string  product_id      = robot._loadedItems.Peek();
            Product current_product = _DicItems[product_id];

            foreach (Order order in _PickOrders)
            {
                Product another_product = _DicItems[order._productID];
                if (another_product._shipperID == current_product._shipperID)
                {
                    return(order);
                }
            }
            return(null);
        }
Exemple #8
0
        private TransportRobot FindTransporterToSlot(Point location)
        {
            TransportRobot select_robot     = null;
            int            current_distance = 0;

            foreach (TransportRobot robot in _TransporterForSlot.Values)
            {
                if (robot._state == robot_state.free || robot._state == robot_state.returning)
                {
                    int new_distance = AStarPathfinding.ComputeHScore(robot._location.X, robot._location.Y, location.X, location.Y);

                    if (select_robot == null || new_distance < current_distance)
                    {
                        select_robot     = robot;
                        current_distance = new_distance;
                    }
                }
            }

            return(select_robot);
        }
Exemple #9
0
        protected void Slot(int sec)
        {
            if (_pickingTime < 9)
            {
                if (_pickingTime == 0) // start picking
                {
                    if (sec + 10 > 59)
                    {
                        _actionString += " n";
                        return;
                    }

                    transporter = GetAdjacentTransporter();
                    if (transporter == null)
                    {
                        _actionString += " n";
                        return;
                    }

                    _actionString            = _actionString + " s " + transporter._id + " " + _order._rack.GetXXYYDH() + " " + transporter._loadedItems.Peek();
                    transporter._isUnloading = true;
                    this._isUnloading        = true;
                    Program.PrintLine(transporter._id + "begin slot" + transporter._isLoading + transporter._isUnloading);
                }
                _pickingTime++;
            }
            else // finish slot
            {
                _pickingTime = 0;
                _order._quantity--;
                _order._rack.AddItem(transporter._loadedItems.Dequeue());
                transporter.FinishSlotting();
                this._isUnloading = false;
                if (_order._quantity == 0)
                {
                    PrepareToReturn();
                }
            }
        }
Exemple #10
0
        protected void Pick(int sec)
        {
            if (_pickingTime < 9)
            {
                if (_pickingTime == 0) // start picking
                {
                    if (sec + 10 > 59)
                    {
                        _actionString += " n";
                        return;
                    }

                    transporter = GetAdjacentTransporter();
                    if (transporter == null)
                    {
                        _actionString += " n";
                        return;
                    }
                    _actionString          = _actionString + " p " + transporter._id + " " + _order._rack.GetXXYYDH() + " " + _order._productID;
                    transporter._isLoading = true;
                    this._isLoading        = true;
                    Program.PrintLine(transporter._id + "begin pick" + transporter._isLoading + transporter._isUnloading);
                }
                _pickingTime++;
            }
            else // finish picking
            {
                _pickingTime = 0;
                _order._quantity--;
                _order._rack.RemoveItem(_order._productID);
                transporter.FinishPicking();
                this._isLoading = false;
                if (_order._quantity == 0)
                {
                    transporter.PrepareToShip();
                    PrepareToReturn();
                }
            }
        }
Exemple #11
0
        public override void GenerateAction(int sec)
        {
            if (sec == 0)
            {
                _actionString = _id.ToString(); // add id at sec 0
                if (_noPath)
                {
                    Program.Print("Refind path from " + _location + " to " + _destination_point + "\n");
                    _path = AStarPathfinding.FindPath(_location, _destination_point, out _noPath);
                }
            }

            if (_noPath)
            {
                _actionString += " n";
                return;
            }

            if (_state == robot_state.free) // no action
            {
                _actionString += " n";
            }
            else if (_path.Count > 0) // moving
            {
                if (Rotate() == true)
                {
                    return;
                }

                Byte robot_id = Warehouse.ValueAt(_path.Peek());
                if (robot_id == 0 || robot_id == 1) // No robot standing at this tile, road is clear
                {
                    MoveToNextTile();
                }
                else // new location is obstructed
                {
                    _actionString += " n";
                    Robot another_robot = Warehouse._AllMovingRobots[robot_id];
                    if (another_robot._path.Count == 0)// anther robot is stopping
                    {
                        Program.Print(_id + " is obstructed by " + robot_id + another_robot._state + " at " + _path.Peek() + "\n");
                        if (Warehouse._Transporters.ContainsKey(another_robot._id) && _destination_point.Equals(another_robot._destination_point))
                        {
                            TransportRobot robot = (TransportRobot)another_robot;
                            robot.LeavePathForPicker();
                            return;
                        }
                        if (another_robot._state == robot_state.slot || another_robot._state == robot_state.pick)
                        {
                            another_robot.AvoidToLeavePath();
                        }
                    }
                    else if (IsCollideWith(another_robot))
                    {
                        Program.Print(_id + "" + _location + "collide with " + robot_id + _path.Peek() + "\n");
                        if (another_robot._state == robot_state.slot || another_robot._state == robot_state.pick)
                        {
                            if (another_robot.AvoidToLeavePath() == false)
                            {
                                this.AvoidToLeavePath();
                            }
                        }
                        else
                        {
                            AvoidToLeavePath();
                        }
                    }
                }
            }
            else // we arrive at the destination
            {
                if (_state == robot_state.returning) // robot return to charging point
                {
                    if (Rotate(Direction.Up) == false) // rotate to upward position
                    {
                        _state         = robot_state.free;
                        _actionString += " n";
                    }
                }
                else if (_state == robot_state.pick && _order._quantity > 0)
                {
                    Pick(sec);
                }
                else if (_state == robot_state.slot && _order._quantity > 0)
                {
                    Slot(sec);
                }
            }
        }
Exemple #12
0
 public PickingRobot(int x, int y, Byte id) : base(x, y, id)
 {
     _pickingTime = 0;
     transporter  = null;
     type         = "picker";
 }
Exemple #13
0
        public void Pick(List <string> input)
        {
            for (int i = 1; i < input.Count; i += 2) // Add new order into the list
            {
                Order new_order      = new Order(input[i], int.Parse(input[i + 1]));
                Order existing_order = _PickOrders.FirstOrDefault(x => x._productID.Equals(new_order._productID));
                if (existing_order != null)
                {
                    existing_order._quantity += new_order._quantity;
                }
                else
                {
                    _PickOrders.Add(new_order);
                }
            }

            if (_time == 0 && _day != 0) // resume the activity of previous day
            {
                foreach (Robot robot in _AllMovingRobots.Values)
                {
                    robot.ResumeActivityLastDay();
                }
            }

            if (_time < 714)
            {
                while (_PickOrders.Count > 0)
                {
                    Order order         = FindOrderToHandle();
                    int   NumItemInRack = 0;

                    // Find rack contains order product
                    Rack rack = FindRackToPick(order, out NumItemInRack);
                    if (rack == null)
                    {
                        Program.PrintLine("Can not find rack contain the product");
                        _PickOrders.Remove(order);
                        continue;
                    }

                    // Get the pickup point of rack
                    Point pickup_point = rack.GetPickUpPoint();

                    // Find picking robot which is free and near rack
                    Robot picker = FindPickerToPick(rack);
                    if (picker == null) // All pickers are busy
                    {
                        //Program.Print("All pickers are busy");
                        return;
                    }

                    TransportRobot transporter = FindTransporterToPick(rack._location);
                    if (transporter == null) // All transporters are busy
                    {
                        //Program.Print("All transporters are busy");
                        return;
                    }

                    rack._expectedPickQuantity = (order._quantity > NumItemInRack) ? NumItemInRack : order._quantity;
                    order._quantity           -= rack._expectedPickQuantity;
                    if (order._quantity <= 0) // Get enought quantity, remove order from the list of orders
                    {
                        _PickOrders.Remove(order);
                    }

                    picker.PrepareToPick(pickup_point, rack, order._productID, rack._expectedPickQuantity);
                    transporter.PrepareToPick(pickup_point, rack, order._productID, rack._expectedPickQuantity);
                    Program.Print("Handle pick " + order._productID + " " + rack._expectedPickQuantity);
                }
            }
            //else
            //{
            //    foreach (Robot robot in _AllMovingRobots.Values)
            //    {
            //        robot.ForceReturnChargingPoint();
            //    }
            //}
        }