Example #1
0
        public override bool Reroute()
        {
            switch (_state)
            {
            case robot_state.pick:
            case robot_state.slot:
                if (_path.Count == 0)
                {
                    Program.Print(_id + "do not reroute \n");
                    return(false);
                }
                Program.Print(_id + "pick slot reroute to " + _destination_point + "\n");
                _path = AStarPathfinding.FindPath(_location, _destination_point, out _noPath);
                return(true);

            case robot_state.returning:
                if (_path.Count == 0)
                {
                    Program.Print(_id + "do not reroute \n");
                    return(false);
                }
                Program.Print(_id + "return reroute to " + _destination_point + "\n");
                _path = AStarPathfinding.FindPath(_location, _chargingPoint, out _noPath);
                return(true);

            default:
                Program.Print(_id + "do not reroute \n");
                return(false);
            }
        }
Example #2
0
        public override bool Reroute()
        {
            if (_isLoading == true || _isUnloading == true)
            {
                return(false);
            }

            switch (_state)
            {
            case robot_state.pick:
            case robot_state.slot:
                _path = AStarPathfinding.FindPath(_location, _destination_point, out _noPath);
                if (_path.Count > 0)
                {
                    return(true);
                }
                return(false);

            case robot_state.ship:
                if (_path.Count == 0)
                {
                    return(false);
                }
                else
                {
                    Program.Print(_id + "ship reroute to " + _destination_point + "\n");
                    PrepareToShip();
                    return(true);
                }

            case robot_state.receive:
                if (_path.Count == 0)
                {
                    return(false);
                }
                else
                {
                    Program.Print(_id + "recieve reroute to " + _destination_point + "\n");
                    PrepareToReceive();
                    return(true);
                }

            case robot_state.returning:
                if (_path.Count == 0)
                {
                    return(false);
                }
                else
                {
                    Program.Print(_id + "return reroute to " + _chargingPoint + "\n");
                    _path = AStarPathfinding.FindPath(_location, _chargingPoint, out _noPath);
                    return(true);
                }

            default:
                Program.Print("Reroute: Unkown state");
                return(false);
            }
        }
Example #3
0
 public override void PrepareToReturn()
 {
     if (_state != robot_state.returning && _state != robot_state.free && _pickingTime == 0)
     {
         _path              = AStarPathfinding.FindPath(_location, _chargingPoint, out _noPath, true);
         _state             = robot_state.returning;
         _destination_point = _chargingPoint;
     }
 }
Example #4
0
        public virtual void PrepareToSlot(Point pickup_point, Rack rack, int quantity)
        {
            _path  = AStarPathfinding.FindPath(_location, pickup_point, out _noPath, true);
            _state = robot_state.slot;

            _order._rack       = rack;
            _order._quantity   = quantity;
            _destination_point = pickup_point;
        }
Example #5
0
        public void PrepareToShip()
        {
            Product       product = Warehouse._DicItems[_loadedItems.Peek()];
            ShippingRobot shipper = (ShippingRobot)Warehouse._Shippers[product._shipperID];

            _destination_point = shipper.GetShipPoint();

            _path  = AStarPathfinding.FindPath(_location, _destination_point, out _noPath, true);
            _state = robot_state.ship;
        }
Example #6
0
 public virtual void ResumeActivityLastDay()
 {
     if (_backUpState != robot_state.free)
     {
         _state       = _backUpState;
         _backUpState = robot_state.free;
         _path        = AStarPathfinding.FindPath(_location, _destination_point, out _noPath);
         Program.Print("Resume: " + _id + " " + _backUpState + " " + _destination_point + "\n");
     }
 }
Example #7
0
        public virtual void PrepareToPick(Point pickup_point, Rack rack, string product_id, int quantity)
        {
            _path  = AStarPathfinding.FindPath(_location, pickup_point, out _noPath, true);
            _state = robot_state.pick;

            _order._rack       = rack;
            _order._productID  = product_id;
            _order._quantity   = quantity;
            _destination_point = pickup_point;
        }
Example #8
0
 public override void ForceReturnChargingPoint()
 {
     if (_state != robot_state.returning && _state != robot_state.free && _pickingTime == 0)
     {
         Program.Print("Force return " + _id + " " + _state + " " + _destination_point + "\n");
         _path = AStarPathfinding.FindPath(_location, _chargingPoint, out _noPath, true);
         if (_noPath == true)
         {
             return;
         }
         _backUpState = _state;
         _state       = robot_state.returning;
     }
 }
Example #9
0
 public void FinishShipping()
 {
     _loadedItems.Dequeue();
     _isUnloading = false;
     if (_loadedItems.Count == 0)   // finish shipping
     {
         if (_order._quantity == 0) // no more item to pick, return to charging point
         {
             PrepareToReturn();
         }
         else
         {
             _state             = robot_state.pick; // return to rack and continue loading item to ship
             _destination_point = _order._rack.GetPickUpPoint();
             _path = AStarPathfinding.FindPath(_location, _destination_point, out _noPath);
         }
     }
 }
Example #10
0
        public bool LeavePathForPicker()
        {
            int x = _destination_point.X;
            int y = _destination_point.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 newgoal in proposedLocations)
            {
                if (Warehouse.ValueAt(newgoal) == 0)
                {
                    Program.PrintLine(_id + "pick or slot reroute to " + newgoal);
                    _path = AStarPathfinding.FindPath(_location, newgoal, out _noPath);
                    return(true);
                }
            }
            return(false);
        }
Example #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);
                }
            }
        }
Example #12
0
 public void PrepareToReceive()
 {
     _destination_point = Warehouse._Receiver.GetReceivePoint();
     _path  = AStarPathfinding.FindPath(_location, _destination_point, out _noPath, true);
     _state = robot_state.receive;
 }
Example #13
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;
            }

            // when picking, stop 1 tile before the pickup point
            if (_path.Count == 1 &&
                _path.Peek().Equals(_destination_point) &&
                (_state == robot_state.pick || _state == robot_state.slot))
            {
                _path.Pop();
            }

            if (_state == robot_state.free) // no action
            {
                _actionString += " n";
            }
            else if (_path.Count > 0) // moving
            {
                Byte robot_id = Warehouse.ValueAt(_path.Peek());
                if (robot_id == 0 || robot_id == 1) // No robot standing at this tile, road is clear
                {
                    if (Rotate() == true)
                    {
                        return;
                    }
                    MoveToNextTile();
                }
                else // new location is obstructed
                {
                    _actionString += " n";
                    Robot another_robot = Warehouse._AllMovingRobots[robot_id];
                    if (another_robot._path.Count == 0)
                    {
                        Program.Print(_id + " is obstructed by " + robot_id + another_robot._state + " at " + _path.Peek() + "\n");
                        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)
                {
                    if (Rotate(Direction.Up) == false)
                    {
                        _state         = robot_state.free;
                        _actionString += " n";
                    }
                }
                else
                {
                    _actionString += " n";
                }
            }
        }