Example #1
0
        public int CountSimpleCommandToAcumulation(ConveyorBasic cb, List <ConveyorBasic> visited, SimpleCraneCommand otherDeck)
        {
            int res = 0;

            if ((cb == null) || visited.Contains(cb) || !(cb is Conveyor) || (cb is Conveyor && (cb as Conveyor).AcumulationMark))
            {
                return(0);
            }
            res = DBService.CountSimpleCraneCommandForTarget(cb.Name, true);
            if (otherDeck != null && cb.Name == otherDeck.Source && otherDeck.Task == SimpleCommand.EnumTask.Drop)
            {
                res++;
            }

            visited.Add(cb);
            if (cb is ConveyorJunction)
            {
                foreach (var item in (cb as ConveyorJunction).RouteDef.Node)
                {
                    res += CountSimpleCommandToAcumulation(item.Next, visited, otherDeck);
                }
            }
            else if (cb.Route != null)
            {
                res += CountSimpleCommandToAcumulation(cb.Route.Next, visited, otherDeck);
            }
            return(res);
        }
Example #2
0
        public List <ConveyorBasic> LocalConveyors(ConveyorBasic cb)
        {
            List <ConveyorBasic> list = new List <ConveyorBasic>();

            LocalConveyors(cb, list);
            return(list);
        }
Example #3
0
/*
 *      private int CalcFreePlace1(Route route, List<ConveyorBasic> visited)
 *      {
 *          int res = 0;
 *          foreach (var r in route.Items)
 *          {
 *              ConveyorBasic cb = r.Next;
 *              if (!(cb is Conveyor))
 *                  return res;
 *              while (cb != r.Final)
 *              {
 *                  Conveyor c = cb as Conveyor;
 *                  if (c.Accumulation && c.Place == null)
 *                      res++;
 *                  cb = cb.Route.Next;
 *              }
 *          }
 *      }
 */

        private int CalcFreePlace(ConveyorBasic cb, List <ConveyorBasic> visited)
        {
            int res = 0;

            if ((cb == null) || visited.Contains(cb) || !(cb is Conveyor))
            {
                return(0);
            }
            if (cb.Place == null)
            {
                res++;
            }

            if ((cb is Conveyor) && (cb as Conveyor).AcumulationMark)
            {
                return(res);
            }

            visited.Add(cb);
            if (cb is ConveyorJunction)
            {
                foreach (var item in (cb as ConveyorJunction).RouteDef.Node)
                {
                    res += CalcFreePlace(item.Next, visited);
                }
            }
            else if (cb.Route != null)
            {
                res += CalcFreePlace(cb.Route.Next, visited);
            }
            return(res);
        }
Example #4
0
        public IConveyorIO CheckForConveyorIO(string name)
        {
            ConveyorBasic cb = FindConveyorBasic(name);

            if (!(cb is IConveyorIO))
            {
                throw new BasicWarehouseException(String.Format("{0} is not IConveyorIO", name));
            }
            return(cb as IConveyorIO);
        }
Example #5
0
        public void ConnectCraneInConveyor(ConveyorBasic tr, RouteNode node)
        {
            Crane c = node.Next as Crane;

            if (c.InConveyor == null)
            {
                c.InConveyor = new List <IConveyorIO>();
            }
            if (!(tr is IConveyorIO)) // && !(tr is ConveyorIOAndOutput) && !(tr is ConveyorJunctionAndIOAndOutput))
            {
                throw new BasicWarehouseException(String.Format("{0} is connected to {1} but does not have IConveyorIO iterface", tr.Name, node.Next.Name));
            }
            c.InConveyor.Add(tr as IConveyorIO); // as ConveyorIO);
        }
Example #6
0
        public ConveyorBasic FindDeviceByPLC_ID(int plc_id)
        {
            ConveyorBasic cb = null;

            cb = ConveyorList.Find(p => p.PLC_ID == plc_id);
            if (cb == null)
            {
                cb = CraneList.Find(p => p.PLC_ID == plc_id);
            }
            if (cb == null)
            {
                throw new BasicWarehouseException(String.Format("BasicWarehouse.FindDeviceByPLC_ID plc_id({0}) does not exist.", plc_id));
            }
            return(cb);
        }
Example #7
0
 private void LocalConveyors(ConveyorBasic cb, List <ConveyorBasic> list)
 {
     if ((cb == null) || list.Contains(cb) || !(cb is Conveyor))
     {
         return;
     }
     list.Add(cb);
     if (cb is ConveyorJunction)
     {
         foreach (var item in (cb as ConveyorJunction).RouteDef.Node)
         {
             LocalConveyors(item.Next, list);
         }
     }
     else if (cb.Route != null)
     {
         LocalConveyors(cb.Route.Next, list);
     }
 }
Example #8
0
 private ConveyorBasic FindNextNonConveyor(ConveyorBasic cb)
 {
     try
     {
         ConveyorBasic res = cb;
         while (res != null)
         {
             if (res is ConveyorJunction || res is IConveyorIO || res is IConveyorOutput || res is Crane || res is IConveyorDefault || res is ConveyorOutputDefault)
             {
                 return(res);
             }
             res = res.Route.Next;
         }
         return(res);
     }
     catch (Exception ex)
     {
         AddEvent(Event.EnumSeverity.Error, Event.EnumType.Exception, ex.Message);
         throw new BasicWarehouseException(String.Format("{0} Graph.FindNextNonCoveyor failed", cb != null ? cb.Name : "null"));
     }
 }
Example #9
0
        public bool RouteExists(string source, string target, bool isSimpleCommand)
        {
            try
            {
                ConveyorBasic deviceSource         = null;
                ConveyorBasic deviceTargetConveyor = null;
                List <Crane>  deviceTargetCrane    = null;

                if (source == null || target == null)
                {
                    return(false);
                }

                // define source
                // search for junction or first device
                if (ConveyorList.Exists(p => p.Name == source))
                {
                    deviceSource = Conveyor[source];
                    while (deviceSource.Route != null)
                    {
                        deviceSource = deviceSource.Route.Next;
                    }
                }
                else if (CraneList.Exists(p => p.Name == source))
                {
                    deviceSource = Crane[source];
                }
                else
                {
                    deviceSource = CraneList.Find(p => p.Shelve.Exists(s => source.StartsWith("W:" + s.ToString())));
                }
                if (deviceSource == null)
                {
                    return(false);
                }
                if (!(deviceSource is ConveyorJunction) && !(deviceSource is ConveyorOutput) && !(deviceSource is ConveyorOutputDefault) && !(deviceSource is Crane))
                {
                    return(false);
                }

                // define target
                if (ConveyorList.Exists(p => p.Name == target))
                {
                    deviceTargetConveyor = Conveyor[target];
                }
                else
                {
                    deviceTargetCrane = CraneList.FindAll(p => p.Shelve.Exists(s => target.StartsWith("W:" + s.ToString())));
                }
                if (deviceTargetConveyor == null && deviceTargetCrane == null)
                {
                    return(false);
                }

                // check if target is in the route
                List <Route> frc = null;
                if (deviceSource is ConveyorJunction)
                {
                    frc = (deviceSource as ConveyorJunction).RouteDef.FinalRouteCost;
                }
                else if (deviceSource is Crane)
                {
                    frc = (deviceSource as Crane).OutRouteDef.FinalRouteCost;
                }
                if (frc == null)
                {
                    return(false);
                }
                if (isSimpleCommand)
                {
                    if (deviceTargetConveyor != null && !frc.Exists(p => p.Items.Exists(s => s.Final.Name == deviceTargetConveyor.Name)))
                    {
                        return(false);
                    }
                    if (deviceTargetCrane != null && !frc.Exists(p => p.Items.Exists(s => deviceTargetCrane.Contains(s.Final as Crane))))
                    {
                        return(false);
                    }
                }
                else
                {
                    if (deviceTargetConveyor != null && !frc.Exists(p => p.Items[p.Items.Count - 1].Final.Name == deviceTargetConveyor.Name))
                    {
                        return(false);
                    }
                    if (deviceTargetCrane != null && !frc.Exists(p => deviceTargetCrane.Contains(p.Items[p.Items.Count - 1].Final as Crane)))
                    {
                        return(false);
                    }
                }

                return(true);
            }
            catch (Exception e)
            {
                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));
                return(false);
            }
        }
Example #10
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...");
        }
Example #11
0
 public int FreePlaces(ConveyorBasic cb)
 {
     return(CalcFreePlace(cb, new List <ConveyorBasic>()));
 }
Example #12
0
        public void CreateMaterial(UInt32 material, string place, int?mfcs_id, bool ignoreMaterialExsists, bool ignorePlaceExsists)
        {
            try
            {
                SimpleCommand c = null;

                DBService.FindMaterialID((int)material, true);
                Place   pm  = DBService.FindMaterial((int)material);
                Place   pp  = DBService.FindPlace(place);
                PlaceID pid = DBService.FindPlaceID(place);

                //if(pm != null && pm.Place1 == "W:out")
                //{
                //    DBService.MaterialDelete(pm.Place1, (int)material);
                //    pm = null;
                //}

                if (!ignoreMaterialExsists && pm != null) // material exists
                {
                    if (mfcs_id.HasValue)
                    {
                        Command cmd = DBService.FindCommandByID(mfcs_id.Value);
                        cmd.Reason = Command.EnumCommandReason.MFCS;
                        cmd.Status = Command.EnumCommandStatus.Canceled;
                        DBService.UpdateCommand(cmd);
                        OnCommandFinish?.Invoke(cmd);
                    }
                }
                else if (!ignorePlaceExsists && pp != null && pid.Size != 999) // place is full
                {
                    if (mfcs_id.HasValue)
                    {
                        Command cmd = DBService.FindCommandByID(mfcs_id.Value);
                        cmd.Reason = Command.EnumCommandReason.LocationFull;
                        cmd.Status = Command.EnumCommandStatus.Canceled;
                        DBService.UpdateCommand(cmd);
                        OnCommandFinish?.Invoke(cmd);
                    }
                }
                else
                {
                    LPosition loc = LPosition.FromString(place);
                    if (!loc.IsWarehouse())
                    {
                        ConveyorBasic cb = FindConveyorBasic(place);
                        if (cb is Conveyor)
                        {
                            DBService.AddSimpleCommand(c = new SimpleConveyorCommand
                            {
                                Command_ID = mfcs_id,
                                Material   = (int)material,
                                Source     = place,
                                Status     = SimpleCommand.EnumStatus.NotActive,
                                Target     = place,
                                Task       = SimpleCommand.EnumTask.Create,
                                Time       = DateTime.Now
                            });
                        }
                        else if (cb is Crane)
                        {
                            DBService.AddSimpleCommand(c = new SimpleCraneCommand
                            {
                                Command_ID = mfcs_id,
                                Material   = (int)material,
                                Source     = place,
                                Status     = SimpleCommand.EnumStatus.NotActive,
                                Task       = SimpleCommand.EnumTask.Create,
                                Time       = DateTime.Now,
                                Unit       = cb.Name
                            });
                        }
                    }
                    else
                    {
                        DBService.MaterialCreate(place, (int)material, true);
                        OnMaterialMove?.Invoke(new Place {
                            Place1 = place, Material = (int)material
                        }, EnumMovementTask.Create);
                        if (mfcs_id.HasValue)
                        {
                            Command cmd = DBService.FindCommandByID(mfcs_id.Value);
                            cmd.Status = Command.EnumCommandStatus.Finished;
                            DBService.UpdateCommand(cmd);
                            OnCommandFinish?.Invoke(cmd);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                AddEvent(Event.EnumSeverity.Error, Event.EnumType.Exception, String.Format("BasicWarehouse.CreateMaterial material({0}),place({1}) failed. Reason :{2}", material, place, ex.Message));
            }
        }