Пример #1
0
        public void BuildRoutes(bool ignoreBlocked)
        {
            int routeIndex = 0;

            try
            {
                visited = new List <ConveyorBasic>();
                foreach (Crane c in Crane.Values)
                {
                    if (!DBService.FindPlaceID(c.Name).Blocked || ignoreBlocked)
                    {
                        visited.Clear();
                        var d = BuildRouteCost(c, 0, ignoreBlocked);
                        if (d.Item2)
                        {
                            if (c.OutRouteDef == null)
                            {
                                c.OutRouteDef = new RouteDef();
                            }
                            c.OutRouteDef.FinalRouteCost = d.Item1;
                        }

                        if (c.OutRouteDef != null)
                        {
                            foreach (Route r in c.OutRouteDef.FinalRouteCost)
                            {
                                AddEvent(Database.Event.EnumSeverity.Event, Database.Event.EnumType.Program, String.Format("New route ({2}): {0}, {1}", c.Name, r.ToString(), ++routeIndex));
                            }
                        }
                    }
                }
                foreach (ConveyorBasic t in ConveyorList)
                {
                    if (t is ConveyorJunction && (!DBService.FindPlaceID(t.Name).Blocked || ignoreBlocked))
                    {
                        ConveyorJunction cj = t as ConveyorJunction;
                        visited.Clear();
                        var d = BuildRouteCost(t, 0, ignoreBlocked);
                        if (d.Item2)
                        {
                            cj.RouteDef.FinalRouteCost = d.Item1;
                        }

                        if (cj.RouteDef.FinalRouteCost != null)
                        {
                            foreach (Route r in cj.RouteDef.FinalRouteCost)
                            {
                                AddEvent(Database.Event.EnumSeverity.Event, Database.Event.EnumType.Program, String.Format("New route ({2}): {0}, {1}", cj.Name, r.ToString(), ++routeIndex));
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                AddEvent(Event.EnumSeverity.Error, Event.EnumType.Exception, ex.Message);
                throw new BasicWarehouseException(String.Format("{0} Warehouse.BuildRoutes failed", Name));
            }
        }
Пример #2
0
        public bool AllowRoute(ConveyorJunction cj, Route r)
        {
            switch (cj.Name)
            {
            case "T031":
                if (r.Items.Last().Final.Name.StartsWith("C2"))
                {
                    int availablePlaces = 4;

                    List <string> convs = new List <string>(new string[] { "T032", "T033", "T034", "T035", "T211", "T212", "T213", "T214" });
                    foreach (var c in convs)
                    {
                        if (Conveyor[c].Place != null && DBService.FindCommandByPlaceID(c) != null &&
                            (DBService.FindCommandByPlaceID(c) as CommandMaterial).Target.StartsWith("W:2"))
                        {
                            availablePlaces--;
                        }
                    }

                    return(availablePlaces > 0);
                }
                return(true);

            case "T125":
                if (Conveyor["T032"].Place != null)
                {
                    return(false);
                }
                return(true);

            case "T225":
                if (Conveyor["T036"].Place != null)
                {
                    return(false);
                }
                return(true);

            default:
                return(true);
            }
        }
Пример #3
0
        private Tuple <List <Route>, bool> BuildRouteCost(ConveyorBasic t, int level, bool ignoreBlocked)
        {
            if (visited.Contains(t))
            {
                return(new Tuple <List <Route>, bool>(null, false));
            }
            if (t is ConveyorJunction)
            {
                visited.Add(t);
                ConveyorJunction           jt     = t as ConveyorJunction;
                List <Route>               newRes = new List <Route>();
                Tuple <List <Route>, bool> res    = null;
                foreach (RouteNode jt1 in jt.RouteDef.Node)
                {
                    ConveyorBasic final = FindNextNonConveyor(jt1.Next);
                    if (final == null || (!ignoreBlocked && DBService.FindPlaceID(final.Name).Blocked))
                    {
                        res = new Tuple <List <Route>, bool>(new List <Route>(), true);
                    }
                    else
                    {
                        res = BuildRouteCost(final, level + 1, ignoreBlocked);
                    }

                    if (res.Item2)
                    {
                        RouteDescription rd = new RouteDescription {
                            First = jt, Next = jt1.Next, Final = final
                        };
                        res.Item1.ForEach(p => { p.Items.Insert(0, rd); p.Cost += jt1.Cost; });
                        res.Item1.ForEach(p => newRes.Add(p));
                    }
                }
                if (t is IConveyorOutput && level > 0)
                {
                    RouteDescription rd = new RouteDescription {
                        First = t, Next = t, Final = t
                    };
                    newRes.Add(new Route {
                        Cost = 0, Items = new List <RouteDescription> {
                            rd
                        }
                    });
                }
                visited.Remove(t);
                return(new Tuple <List <Route>, bool>(newRes, newRes.Count > 0));
            }
            else if (t is Crane)
            {
                visited.Add(t);
                Crane        jt     = t as Crane;
                List <Route> newRes = new List <Route>();

                // crane could be final location
                bool shuttle = !jt.FinalDevice;
                if (jt.Shelve != null && jt.Shelve.Count > 0)
                {
                    RouteDescription rd = new RouteDescription {
                        First = jt, Next = jt, Final = jt
                    };
                    newRes.Add(new Route {
                        Items = new List <RouteDescription> {
                            rd
                        }, Cost = 0
                    });
                }

                Tuple <List <Route>, bool> res = null;

                if (jt.OutRouteDef != null && jt.OutRouteDef.Node != null)
                {
                    foreach (RouteNode jt1 in jt.OutRouteDef.Node)
                    {
                        ConveyorBasic final = FindNextNonConveyor(jt1.Next);
                        if (final == null || (!ignoreBlocked && DBService.FindPlaceID(final.Name).Blocked))
                        {
                            res = new Tuple <List <Route>, bool>(new List <Route>(), true);
                        }
                        else
                        {
                            res = BuildRouteCost(final, level + 1, ignoreBlocked);
                        }

                        if (res.Item2 && (level == 0 || shuttle))
                        {
                            RouteDescription rd = new RouteDescription {
                                First = jt, Next = jt1.Next, Final = final
                            };
                            res.Item1.ForEach(p => { p.Items.Insert(0, rd); p.Cost += jt1.Cost; });
                            res.Item1.ForEach(p => newRes.Add(p));
                        }
                    }
                }
                visited.Remove(t);
                return(new Tuple <List <Route>, bool>(newRes, newRes.Count > 0));
            }
            else if (t is IConveyorOutput)
            {
                RouteDescription rd = new RouteDescription {
                    First = t, Next = t, Final = t
                };
                return(new Tuple <List <Route>, bool>(new List <Route> {
                    new Route {
                        Cost = 0, Items = new List <RouteDescription> {
                            rd
                        }
                    }
                }, true));
            }
            throw new BasicWarehouseException("Unknown type in path calculation...");
        }