Пример #1
0
        public SimpleCraneCommand FindBestOutput(CommandMaterial cmd)
        {
            try
            {
                var routes = from route in OutRouteDef.FinalRouteCost
                             where route.Items.Last().Final.Compatible(cmd.Target) && route.Items[0].Next.Place == null && route.Items[0].Final is Conveyor
                             group route by new { Route = route.Items[0] } into Group
                    select new
                {
                    Node1     = Group.Key.Route,
                    RouteCost = Group.Min((x) => x.Cost)
                };

                if (routes.Count() > 0)
                {
                    var route = routes.ElementAt(Random.Next(routes.Count())); // -1
                    return(new SimpleCraneCommand
                    {
                        Command_ID = cmd.ID,
                        Material = (int)cmd.Material,
                        Source = route.Node1.Final.Name,
                        Unit = Name,
                        Task = SimpleCommand.EnumTask.Drop,
                        Status = SimpleCommand.EnumStatus.NotInDB,
                        Time = DateTime.Now
                    });
                }
                return(null);
            }
            catch (Exception ex)
            {
                Warehouse.AddEvent(Event.EnumSeverity.Error, Event.EnumType.Exception, ex.Message);
                throw new CraneException(String.Format("{0} Crane.FindBestOutput failed {1}", Name, cmd != null ? cmd.ToString() : "null"));
            }
        }
Пример #2
0
        public void ExecuteConfirm()
        {
            IsEnabledField = false;
            IsEnabledCC    = false;
            IsInDeleteMode = false;
            try
            {
                switch (_selectedCommand)
                {
                case CommandType.AddMaterial:
                    DetailedContent.Time = DateTime.Now;
                    CommandMaterial cmd = DetailedContent.Command as CommandMaterial;
                    if (cmd.Material != null)
                    {
                        _warehouse.DBService.FindMaterialID(cmd.Material.Value, true);
                    }
                    _warehouse.DBService.AddCommand(cmd);
                    CommandList.Add(DetailedContent);
                    break;

                case CommandType.AddSegment:
                    DetailedContent.Time = DateTime.Now;
                    _warehouse.DBService.AddCommand(DetailedContent.Command as CommandSegment);
                    CommandList.Add(DetailedContent);
                    break;

                case CommandType.Restart:
                    DetailedContent.Time   = DateTime.Now;
                    DetailedContent.Status = EnumCommandStatus.Waiting;
                    _warehouse.DBService.UpdateCommand(DetailedContent.Command);
                    break;

                case CommandType.Delete:
                    _warehouse.DBService.UpdateCommand(DetailedContent.Command);
                    _warehouse.DBService.AddCommand(new CommandCommand
                    {
                        Task      = Command.EnumCommandTask.CancelCommand,
                        CommandID = DetailedContent.ID,
                        Priority  = 0,
                        Status    = Command.EnumCommandStatus.NotActive,
//                            Reason = DetailedContent.Command.Reason,
                        Time = DateTime.Now
                    });
                    break;

                default:
                    break;
                }
                DetailedContent.ValidationEnabled = false;
                DetailedContent = SelectedContent;
            }
            catch (Exception e)
            {
                _warehouse.AddEvent(Database.Event.EnumSeverity.Error, Database.Event.EnumType.Exception,
                                    string.Format("{0}.{1}: {2}", this.GetType().Name, (new StackTrace()).GetFrame(0).GetMethod().Name, e.Message));
            }
        }
Пример #3
0
        public SimpleCraneCommand FindBestWarehouse(bool automatic, List <string> bannedPlaces, SimpleCraneCommand otherDeck)
        {
            try
            {
                CommandMaterial cmd   = Warehouse.DBService.FindFirstCommandStillInWarehouse(Shelve, automatic, bannedPlaces);
                bool            found = false;
                if (cmd != null)
                {
                    foreach (var route in OutRouteDef.FinalRouteCost)
                    {
                        if (route.Items.Last().Final.Compatible(cmd.Target))  // && route.Items[0].Final.Place == null)
                        {
                            int cnt = Warehouse.CountSimpleCommandToAcumulation(route.Items[0].Final, new List <ConveyorBasic>(), otherDeck);
                            if (Warehouse.FreePlaces(route.Items[0].Final) > cnt ||
                                route.Items[0].Final is Crane)
                            {
                                int a = Warehouse.FreePlaces(route.Items[0].Final);
                                int b = Warehouse.DBService.CountSimpleCraneCommandForTarget(route.Items[0].Final.Name, true);
                                Warehouse.AddEvent(Event.EnumSeverity.Event, Event.EnumType.Program, String.Format("FindBestWarehouse On {0} Free places {1} Incoming commands {2}", route.Items[0].Final.Name, a, b));
                                found = true;
                                break;
                            }
                        }
                    }

                    if (found)
                    {
                        return new SimpleCraneCommand
                               {
                                   Command_ID = cmd.ID,
                                   Material   = (int)cmd.Material,
                                   Source     = cmd.Source,
                                   Unit       = Name,
                                   Task       = SimpleCommand.EnumTask.Pick,
                                   Status     = SimpleCommand.EnumStatus.NotInDB,
                                   Time       = DateTime.Now
                               }
                    }
                    ;
                }
                return(null);
            }
            catch (Exception ex)
            {
                Warehouse.AddEvent(Event.EnumSeverity.Error, Event.EnumType.Exception, ex.Message);
                throw new CraneException(String.Format("{0} Crane.FindBestWarehouse failed ({1})", Name, automatic));
            }
        }
Пример #4
0
 public void CommandMaterialAdd(CommandMaterial cmd)
 {
     try
     {
         DBService.AddCommand(cmd);
         if (cmd.Task == Command.EnumCommandTask.CreateMaterial)
         {
             CreateMaterial((uint)cmd.Material.Value, cmd.Source, cmd.ID, false, false);
         }
         if (cmd.Task == Command.EnumCommandTask.DeleteMaterial)
         {
             DeleteMaterial((uint)cmd.Material.Value, cmd.Source, cmd.ID);
         }
     }
     catch (Exception e)
     {
         throw new Exception(string.Format("{0}.{1}: {2}", this.GetType().Name, (new StackTrace()).GetFrame(0).GetMethod().Name, e.Message));
     }
 }
Пример #5
0
        public SimpleCraneCommand FindBestInput(bool automatic, IConveyorIO forcedInput)
        {
            try
            {
                CommandMaterial  cmd = null;
                List <BestInput> res = new List <BestInput>();

                foreach (ConveyorJunction c in InConveyor)
                {
                    if (c.Place != null)
                    {
                        cmd = Warehouse.DBService.FindFirstCommand(c.Place.Material, automatic);
                        if (cmd != null)
                        {
                            bool check = (c.ActiveRoute != null) && (c.ActiveRoute.Items[0].Final is Crane) && (c.ActiveRoute.Items[0].Final.Name == Name) && (c.ActiveMaterial == cmd.Material);
                            check = check && !Warehouse.DBService.CheckIfSimpleCraneCommandToPlaceMaterialExist(c.Place, automatic);
                            if (check)
                            {
                                Warehouse.AddEvent(Event.EnumSeverity.Event, Event.EnumType.Program, $"{Name}.FindBestInput({automatic},{forcedInput?.ToString()}");
                                foreach (var route in OutRouteDef.FinalRouteCost)
                                {
                                    if (route.Items.Last().Final.Compatible(cmd.Target))  // && route.Items[0].Final.Place == null)
                                    {
                                        if ((Warehouse.FreePlaces(route.Items[0].Final) > Warehouse.DBService.CountSimpleCraneCommandForTarget(route.Items[0].Final.Name, true)) ||
                                            route.Items[0].Final is Crane)
                                        {
                                            int a = Warehouse.FreePlaces(route.Items[0].Final);
                                            int b = Warehouse.DBService.CountSimpleCraneCommandForTarget(route.Items[0].Final.Name, true);
                                            Warehouse.AddEvent(Event.EnumSeverity.Event, Event.EnumType.Program, String.Format("FindBestInput On {0} Free places {1} Incoming commands {2}", route.Items[0].Final.Name, a, b));
                                            res.Add(new BestInput {
                                                ID = cmd.ID, Place = c.Name, Material = cmd.Material
                                            });
                                            if ((forcedInput != null && forcedInput == c))
                                            {
                                                res.Clear();
                                                res.Add(new BestInput {
                                                    ID = cmd.ID, Place = c.Name, Material = cmd.Material
                                                });
                                                break;
                                            }
                                        }
                                    }
                                }

                                /*                            var routes = from route in OutRouteDef.FinalRouteCost
                                 *                                       where route.Items.Last().Final.Compatible(cmd.Target) && route.Items[0].Next.Place == null &&
                                 *                                       (route.Items[0].Final is Crane || route.Items[0].Final.Place == null)
                                 *                                       group route by new { Route = route.Items[0] } into Group
                                 *                                       select new
                                 *                                       {
                                 *                                           Node1 = Group.Key.Route,
                                 *                                           RouteCost = Group.Min((x) => x.Cost)
                                 *                                       };
                                 */
                            }
                        }
                    }
                }

                if (res.Count() > 0)
                {
                    var c = res.ElementAt(Random.Next(res.Count())); // -1
                    return(new SimpleCraneCommand
                    {
                        Command_ID = c.ID,
                        Material = c.Material,
                        Source = c.Place,
                        Unit = Name,
                        Task = SimpleCommand.EnumTask.Pick,
                        Status = SimpleCommand.EnumStatus.NotInDB,
                        Time = DateTime.Now
                    });
                }
                return(null);
            }
            catch (Exception ex)
            {
                Warehouse.AddEvent(Event.EnumSeverity.Error, Event.EnumType.Exception, ex.Message);
                throw new CraneException(String.Format("{0} Crane.FindBestInput failed ({1})", Name, automatic));
            }
        }
Пример #6
0
        public virtual void Strategy()
        {
            try
            {
                lock (_lock)
                {
                    if (!Warehouse.StrategyActive)
                    {
                        return;
                    }

                    if (!Warehouse.SteeringCommands.Run)
                    {
                        return;
                    }

                    if (!CheckIfAllNotified())
                    {
                        return;
                    }

                    // delete ActiveRoute
                    if ((Place == null) || (Place.Material != ActiveMaterial))
                    {
                        ActiveRoute    = null;
                        ActiveMaterial = null;
                    }

                    if (ConveyorNamesOnCommunicator == null)
                    {
                        ConveyorNamesOnCommunicator = FillAllConveyorNamesOnCommunicator();
                    }


                    if (Command != null && Place != null && Command.Material != Place.Material)
                    {
                        Command = null;
                        throw new ConveyorJunctionException(String.Format("Command {0} does not match Place {1},{2}", Command.ToString(), Place.Place1, Place.Material));
                    }

                    if (Command == null)
                    {
                        SimpleCommand cmd = Warehouse.DBService.FindFirstFastConveyorSimpleCommand(ConveyorNamesOnCommunicator[CommunicatorName], Warehouse.SteeringCommands.AutomaticMode);

                        // FastCommand could be connected to any Conveyor
                        if (cmd != null)
                        {
                            Conveyor cb = Warehouse.Conveyor[cmd.Source];
                            cb.Command = cmd;
                            CreateAndSendTOTelegram(cmd);
                        }
                    }

                    if (ActiveRoute != null)
                    {
                        return;
                    }

                    if (Command == null && Place != null &&
                        Warehouse.Conveyor[Name].Remote() && Warehouse.Conveyor[Name].Automatic())     // Uros
                    {
                        if (!Warehouse.SteeringCommands.RemoteMode && !Warehouse.SteeringCommands.AutomaticMode)
                        {
                            Command = Warehouse.DBService.FindFirstSimpleConveyorCommand(Place.Material, Name, false);
                            if (Command != null)
                            {
                                CreateAndSendTOTelegram(Command);
                            }
                        }
                        else if (Warehouse.SteeringCommands.AutomaticMode)
                        {
                            CommandMaterial cmd   = Warehouse.DBService.FindFirstCommand(Place.Material, Warehouse.SteeringCommands.RemoteMode);
                            bool            error = false;
                            // check if dimension check failed
                            if (!(this is ConveyorJunctionAndIOAndOutput) &&
                                Command_Status != null && (int)Command_Status.Palette.Barcode == Place.Material)
                            {
                                foreach (bool b in Command_Status.Palette.FaultCode)
                                {
                                    if (b)
                                    {
                                        error = true;
                                        break;
                                    }
                                }
                            }
                            // check for double barcode
                            Place p = Warehouse.DBService.FindMaterial(Place.Material); // ((int)Command_Status.Palette.Barcode);
                            if (p != null && p.Place1 != Name)
                            {
                                error = true;
                            }

                            // follow command
                            if (cmd != null && !error)
                            {
                                var routes = from route in RouteDef.FinalRouteCost
                                             where route.Items.Last().Final.Compatible(cmd.Target) && Warehouse.AllowRoute(this, route) // && route.Items[0].Final is Conveyor
                                             select route;

                                if (routes.Count() > 1)
                                {
                                    routes = from route in RouteDef.FinalRouteCost
                                             where route.Items.Last().Final.Compatible(cmd.Target) && route.Items[0].Final is Conveyor && Warehouse.AllowRoute(this, route) && Warehouse.FreePlaces(route.Items[0].Next) > 0
                                             select route;
                                }

                                // transport command handle
                                if (routes.Count() > 0)
                                {
                                    ActiveRoute    = routes.ElementAt(Random.Next(routes.Count())); // -1
                                    ActiveMaterial = cmd.Material;
                                    Warehouse.DBService.AddSimpleCommand(
                                        Command = new SimpleConveyorCommand
                                    {
                                        Command_ID = cmd.ID,
                                        Material   = (int)cmd.Material,
                                        Source     = ActiveRoute.Items[0].First.Name,
                                        Target     = ActiveRoute.Items[0].Final.Name,
                                        Task       = SimpleCommand.EnumTask.Move,
                                        Status     = SimpleCommand.EnumStatus.NotActive,
                                        Time       = DateTime.Now
                                    });
                                    CreateAndSendTOTelegram(Command);
                                }
                                // crane command demand...
                                else
                                {
                                    routes = from route in RouteDef.FinalRouteCost
                                             where route.Items.Last().Final.Compatible(cmd.Target) && route.Items[0].Final is Crane
                                             select route;
                                    if (routes.Count() > 0)
                                    {
                                        ActiveRoute    = routes.ElementAt(Random.Next(routes.Count())); // -1
                                        ActiveMaterial = cmd.Material;
                                    }
                                }
                            }
                            // default route to output
                            else if (error)
                            {
                                var routes = from route in RouteDef.FinalRouteCost
                                             where route.Items[0].Next.Place == null && route.Items[0].Final is IConveyorDefault
                                             group route by new { Route = route.Items[0] } into Group
                                    select new
                                {
                                    Node1     = Group.Key.Route,
                                    RouteCost = Group.Min((x) => x.Cost)
                                };
                                if (routes.Count() > 0)
                                {
                                    int?cmdid = null;
                                    if (cmd != null)
                                    {
                                        cmdid = cmd.ID;
                                    }
                                    var route = routes.ElementAt(Random.Next(routes.Count()));  // -1
                                    Warehouse.DBService.AddSimpleCommand(
                                        Command = new SimpleConveyorCommand
                                    {
                                        Command_ID = cmdid,
                                        Material   = (int)Place.Material,
                                        Source     = route.Node1.First.Name,
                                        Target     = route.Node1.Final.Name,
                                        Task       = SimpleCommand.EnumTask.Move,
                                        Status     = SimpleCommand.EnumStatus.NotActive,
                                        Time       = DateTime.Now
                                    });
                                    CreateAndSendTOTelegram(Command);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Warehouse.AddEvent(Event.EnumSeverity.Error, Event.EnumType.Exception, ex.Message);
                throw new ConveyorJunctionException(String.Format("{0} ConveyorJunction.Strategy failed ", Name));
            }
        }