Example #1
0
        public static bool IsInMyWay(MachineObject machineObject, AreaToCover areaToCover)
        {
            string coverlineID = areaToCover.GetLastCoverLine(machineObject.VerticalPosition);
            string reciverMachineID = string.Empty;
            try
            {
                reciverMachineID = World.CoverLinesList.Where(a => a.CoverLineID == coverlineID).First().MachineID;
            }
            catch { }

            if (string.IsNullOrEmpty(reciverMachineID))
                return false;

            Request request = new Communication.Request();

            request.RequestType = Communication.Enum.RequestType.CoverLineFinishStatus;
            request.SenderMachineID = machineObject.MachineID;
            request.ReceiverMachineID = reciverMachineID;
            request.CommunicationRequestID = (++World.CommunicationRequestID).ToString();

            Response response = request.Send();

            if (response.CoverLineFinish.MachineActualCoverLineDirection == World.GetCoverLineByID(machineObject.ActualCoverLineID).CoverLineDirection)
            {
                Coordinates a;
                Coordinates b;

                if ((World.CoverDirection == Enumerations.CoverDirection.leftToRight && machineObject.VerticalPosition == Enumerations.VerticalPosition.down)
                    || (World.CoverDirection == Enumerations.CoverDirection.rightToLeft && machineObject.VerticalPosition == Enumerations.VerticalPosition.up))
                {
                    a = areaToCover.LeftDown;
                    b = areaToCover.LeftUp;
                }

                else if ((World.CoverDirection == Enumerations.CoverDirection.leftToRight && machineObject.VerticalPosition == Enumerations.VerticalPosition.up)
                    || (World.CoverDirection == Enumerations.CoverDirection.rightToLeft && machineObject.VerticalPosition == Enumerations.VerticalPosition.down))
                {
                    a = areaToCover.RightDown;
                    b = areaToCover.RightUp;
                }

                else
                {
                    //TODO: minor - if coverDirection == both

                    a = areaToCover.RightDown;
                    b = areaToCover.RightUp;
                }

                //if the finishing time of cover line in front of current machine is smaller, then take this cover line
                if (response.CoverLineFinish.CoverLineFinishTime < DateTime.Now.AddSeconds(Helpers.Methods.GetCoveringTimeSeconds(a, b, machineObject.CoverSpeed)))
                    return true;
                else
                    return false;

            }
            //if the directions are same, machine are going opposite
            else
                return false;
        }
Example #2
0
 public CoverObject(AreaToCover coverArea, MachineObject machine, Coordinates machinePosition, Coordinates direction)
 {
     CoverArea = coverArea;
     MachineObject = machine;
     MachinePosition = machinePosition;
     Direction = direction;
 }
Example #3
0
        /// <summary>
        /// Use when you want to make a copy of existing AreaToCover
        /// </summary>
        /// <param name="area"></param>
        public AreaToCover(AreaToCover area)
        {
            CoordinateList = new List<Coordinates>();

            foreach (var coordinate in area.CoordinateList)
            {
                CoordinateList.Add(new Coordinates(coordinate.X, coordinate.Y));
            }
            AreaToCoverID = World.AreaToCoverIDCounter++.ToString();
        }
Example #4
0
        public Initialization()
        {
            List<double> polygonAreaLatLong = new List<double>() { 17.67187122670222, 48.32100658917706, 17.67484528773948, 48.32276918841107, 17.6676882146302, 48.32648733112465, 17.66670214849421, 48.32374398467304, 17.66727282922581, 48.32347466588006, 17.66717808563941, 48.32291408299006, 17.67187122670222, 48.32100658917706,};

            //MachineObject machine = new MachineObject();
            //machine.CoverSpeed = 1;
            //machine.Position = new Coordinates(0, 0);
            //machine.TransportSpeed = (decimal)3.33;
            //machine.TurningRadius = 10;
            //machine.WorkingWidth = (decimal)7.4;

            //machine = new MachineObject();
            //machine.CoverSpeed = 1;
            //machine.Position = new Coordinates(0, 0);
            //machine.TransportSpeed = (decimal)3.33;
            //machine.TurningRadius = 10;
            //machine.WorkingWidth = (decimal)7.4;

            //Machines.AddMachineToList(machine);

            //machine = new MachineObject();
            //machine.CoverSpeed = (decimal)1.5;
            //machine.Position = new Coordinates(0, 0);
            //machine.TransportSpeed = (decimal)3.33;
            //machine.TurningRadius = 10;
            //machine.WorkingWidth = (decimal)6.6;

            //machine = new MachineObject();
            //machine.CoverSpeed = (decimal)1.8;
            //machine.Position = new Coordinates(0, 0);
            //machine.TransportSpeed = (decimal)3.33;
            //machine.TurningRadius = 10;
            //machine.WorkingWidth = (decimal)6.6;

            //Machines.AddMachineToList(machine);

            List<Coordinates> coordinatesList = new List<Coordinates>();
            //coordinatesList.Add(new Coordinates(0, 0));
            //coordinatesList.Add(new Coordinates(100, 0));
            //coordinatesList.Add(new Coordinates(50, 50));

            //Coordinates for Krizovany: 60.38657388264

            //coordinatesList.Add(new Coordinates((decimal)127.2397627,0));
            //coordinatesList.Add(new Coordinates((decimal)419.7334444,0));
            //coordinatesList.Add(new Coordinates((decimal)298.567374, (decimal)659.4758929));
            //coordinatesList.Add(new Coordinates(45, (decimal)444.2060641));
            //coordinatesList.Add(new Coordinates(40, (decimal)409.2714597));
            //coordinatesList.Add(new Coordinates(0, (decimal)375.7627803));

            //coordinatesList.Add(new Coordinates((decimal)57.24240453, (decimal)52.85539337));
            //coordinatesList.Add(new Coordinates((decimal)344.9208035,0));
            //coordinatesList.Add(new Coordinates((decimal)344.9208035, (decimal)670.5));
            //coordinatesList.Add(new Coordinates((decimal)56.62729036, (decimal)504.6097819));
            //coordinatesList.Add(new Coordinates((decimal)45.39670844, (decimal)471.1538316));
            //coordinatesList.Add(new Coordinates(0, (decimal)445.425045));

            //Horenicka Horka
            coordinatesList.Add(new Coordinates((decimal)41.9216369, 0));
            coordinatesList.Add(new Coordinates((decimal)156.9923198, (decimal)15.38859396));
            coordinatesList.Add(new Coordinates((decimal)233.0452109, (decimal)174.7612497));
            coordinatesList.Add(new Coordinates((decimal)341.6539338, (decimal)331.6318502));
            coordinatesList.Add(new Coordinates((decimal)406.1837036, (decimal)517.4414539));
            coordinatesList.Add(new Coordinates((decimal)418.1232184, (decimal)595.8130295));
            coordinatesList.Add(new Coordinates((decimal)310.1985024, (decimal)576.7681963));
            coordinatesList.Add(new Coordinates((decimal)276.7277039, (decimal)874.9837989));
            coordinatesList.Add(new Coordinates((decimal)41.9216369, (decimal)936.7125686));
            coordinatesList.Add(new Coordinates((decimal)14.81192476, (decimal)480.4148294));
            coordinatesList.Add(new Coordinates(0, (decimal)230.1323951));

            //AreaToCover area = new AreaToCover(new Coordinates(100, 100));
            AreaToCover area = new AreaToCover(coordinatesList);

            World.AreasToCover = new List<AreaToCover>();
            World.AreasToCover.Add(area);

            World.CoverLinesList = new List<CoverLine>();
        }
Example #5
0
        /// <summary>
        /// Orders List<AreaToCover> from the best to the worst due to machine position.
        /// </summary>
        /// <param name="machinePositionToCoverArea"></param>
        /// <returns></returns>
        private List<AreaToCover> OrderAreasToCoverByMachinePosition(int machinePositionToCoverArea)
        {
            AreaToCover[] tempAreaToCover = new AreaToCover[World.AreasToCover.Count];
            World.AreasToCover.CopyTo(tempAreaToCover);
            var tempAreaToCoverList = tempAreaToCover.ToList();

            if (machinePositionToCoverArea > 1 && machinePositionToCoverArea < 4)
                tempAreaToCoverList.Reverse();

            return tempAreaToCoverList;
        }
Example #6
0
        private CoverLine DivideCoverArea(Enumerations.MachinePositionToCoverArea machinePosition, string areaToCoverID)
        {
            //TODO:critical - DivideCoverArea;

            List<string> machinesWithMeIDs = World.GetMachinesToBeOnTheSameCoverArea(areaToCoverID);

            decimal width = this.CalculateWidthToDivide(machinesWithMeIDs);
            CoverLine coverLine;
            AreaToCover oldArea = World.GetAreaByID(areaToCoverID);
            AreaToCover newArea = new AreaToCover(oldArea);

            World.AreasToCover.Add(newArea);

            if ((int)machinePosition > 2 && World.CoverDirection == Enumerations.CoverDirection.leftToRight)
            {
                coverLine = World.GetAreaByID(areaToCoverID).GetLineFromLeft(width, WorkingWidth);
                oldArea.SetAsDividedLeft(coverLine, WorkingWidth);
                newArea.SetAsDividedRight(coverLine, WorkingWidth);
            }
            else if ((int)machinePosition < 3 && World.CoverDirection == Enumerations.CoverDirection.rightToLeft)
            {
                coverLine = World.GetAreaByID(areaToCoverID).GetLineFromRight(width, WorkingWidth);

            }

            else
                throw new Exception("Should not divide!");

            coverLine.IsDivide = true;
            coverLine.CoverLinePosition = Enumerations.CoverLinePosition.inner;
            coverLine.AreaToCoverID = areaToCoverID;

            return coverLine;
        }