public ConveyorNode DetermineNextNode()
        {
            ConveyorNode tnode = null;

            var g = Peek();

            if (g.IsNull())
            {
                return(null);
            }

            foreach (var p in ListOfConnectedNodes)
            {
                Node currentNode = p;

                while (currentNode.GetNext() != null && !(currentNode is TerminalNode node))
                {
                    currentNode = currentNode.GetNext();
                }

                var result = GetTerminalNumber(g);
                if ((currentNode as TerminalNode)?.Terminal.TerminalId != result)
                {
                    continue;
                }
                tnode = p;
                break;
            }

            return(tnode);
        }
Example #2
0
        public ConveyorNode DetermineNextConveyorNode()
        {
            ConveyorNode tnode = null;
            var          g     = Peek();

            if (g.IsNull())
            {
                return(null);
            }
            foreach (var p in ListOfConnectedNodes)
            {
                Node currentNode = p;

                while (currentNode.GetNext() != null && !(currentNode is GateNode node))
                {
                    currentNode = currentNode.GetNext();
                }

                if (GetGateNumber(g, out var result))
                {
                    return(null);
                }
                if ((currentNode as GateNode)?.Gate.GateNr != result)
                {
                    continue;
                }
                tnode = p;
                break;
            }

            return(tnode);
        }
Example #3
0
        public void PassBag(Bag g)
        {
            Node         next        = (ConveyorNode)determineNextNode(g);
            ConveyorNode tmpConveyor = null;

            while (!(next is TerminalNode))
            {
                if (((ConveyorNode)(next)).IsFull == false)
                {
                    ((ConveyorNode)(next)).PushBagToConveyorBelt(g);
                }

                if (next.Next is TerminalNode)
                {
                    tmpConveyor = (ConveyorNode)next;
                }
                next = ((next).Next);
            }

            var tbag = tmpConveyor.RemoveBagFromConveyorBelt();

            while (tbag == null && !tmpConveyor.IsEmpty())
            {
                tbag = tmpConveyor.RemoveBagFromConveyorBelt();
            }
            if (tbag != null)
            {
                ((TerminalNode)(next)).PassBag(tbag);
            }

            Thread.Sleep(DelayTime);
        }
        public void CreateMapLayout(int QueueSizeOfBelts)
        {
            if (IsMapCreated)
            {
                return;
            }

            Setsize = QueueSizeOfBelts;


            LinkedList.AddNode(new CheckinNode(213, 10));

            LinkedList.AddNode(ConveyorNode = new ConveyorNode(Setsize, 205, 0, 0, 0, 295, 160));

            LinkedList.AddNode(new SecurityNode(246, 355));

            LinkedList.AddNode(ConveyorNode = new ConveyorNode(Setsize, 200, 0, 0, 0, 295, 435));

            BagSortNode = new BagSortNode(257, 630);

            LinkedList.AddNode(BagSortNode);



            LinkedList.AddNode(ConveyorNode = new ConveyorNode(Setsize, 270, 0, -180, 0, 280, 701), BagSortNode);


            t = new TerminalNode(new Terminal("T1"), 70, 952);

            LinkedList.AddNode(t, ConveyorNode);


            LinkedList.AddNode(ConveyorNode = new ConveyorNode(Setsize, 88, 0, 40, 0, 148, 1002), t);


            GateNode = new GateNode(new Gate("G1"), 148, 1114);
            LinkedList.AddNode(GateNode, ConveyorNode);



            LinkedList.AddNode(ConveyorNode = new ConveyorNode(Setsize, 270, 0, 270, 0, 316, 701), BagSortNode);

            t = new TerminalNode(new Terminal("T2"), 536, 952);
            LinkedList.AddNode(t, ConveyorNode);


            LinkedList.AddNode(ConveyorNode = new ConveyorNode(Setsize, 90, 0, 0, 40, 500, 1027), t);

            GateNode = new GateNode(new Gate("G1"), 426, 1128);
            LinkedList.AddNode(GateNode, ConveyorNode);
        }
 public void ConnectNodeToSorter(ConveyorNode n)
 {
     ListOfConnectedNodes.Add(n);
 }
        public static void MoveBags(int totalnr)
        {
            if (TerminalNode.counter + Storage.GetNumberOfBagsInStorage() == totalnr)
            {
                IsSimulationFinished = true;
            }

            if (First != null)
            {
                if (current.Next != null && !(current is GateNode))
                {
                    bool check = true;
                    switch (current.Next)
                    {
                    case ConveyorNode NextNode when current is CheckinNode checkidNode:
                    {
                        if (checkidNode._bagsQueue.Count > 0 && NextNode.IsFull == false)
                        {
                            NextNode.PushBagToConveyorBelt(checkidNode.Remove());
                            Node.log.Add("Added bag to " + NextNode.Id);
                        }
                        break;
                    }

                    case SecurityNode nextNode when current is ConveyorNode conveyorNode:
                    {
                        if (!(nextNode.Next as ConveyorNode).IsFull || !(conveyorNode.IsEmpty()))
                        {
                            var bagToCheck = conveyorNode.RemoveBagFromConveyorBelt();
                            if (bagToCheck != null)
                            {
                                var bagChecked = nextNode.ScanBagSecurity(bagToCheck);
                                if (bagChecked != null)
                                {
                                    ((ConveyorNode)(nextNode.Next)).PushBagToConveyorBelt(bagChecked);
                                }
                                else
                                {
                                    current = first;
                                    check   = false;
                                }
                            }
                            else
                            {
                                current = first;
                                check   = false;
                            }
                        }
                        break;
                    }

                    case BagSortNode node when current is ConveyorNode conveyorNode:
                    {
                        if (!conveyorNode.IsEmpty() && !IsSimulationFinished)
                        {
                            var con = (ConveyorNode)(node.determineNextNode(conveyorNode.ListofBagsinqueue().Peek()));
                            con.PushBagToConveyorBelt(conveyorNode.RemoveBagFromConveyorBelt());

                            current = con;
                            check   = false;

                            //var tbag = conveyorNode.RemoveBagFromConveyorBelt();
                            //if (tbag != null)
                            //{
                            //    check = true;
                            //    node.PassBag(tbag);
                            //}
                        }
                        break;
                    }

                    case TerminalNode terminalNode when current is ConveyorNode conveyorNode:
                    {
                        if (!conveyorNode.IsEmpty() && !IsSimulationFinished)
                        {
                            ConveyorNode con =
                                (ConveyorNode)(terminalNode.determineNextNode(conveyorNode.ListofBagsinqueue()
                                                                              .Peek()));
                            con.PushBagToConveyorBelt(conveyorNode.RemoveBagFromConveyorBelt());

                            current = con;
                            check   = false;
                            //var tbag = conveyorNode.RemoveBagFromConveyorBelt();


                            //if (tbag != null)
                            //{
                            //    check = true;
                            //    node.PassBag(tbag);
                            //}
                        }


                        break;
                    }

                    case GateNode gateNode when current is ConveyorNode conveyorNode:
                    {
                        if (!conveyorNode.IsEmpty() && !IsSimulationFinished)
                        {
                            gateNode.AddBag(conveyorNode.RemoveBagFromConveyorBelt());


                            //var tbag = conveyorNode.RemoveBagFromConveyorBelt();


                            //if (tbag != null)
                            //{
                            //    check = true;
                            //    node.PassBag(tbag);
                            //}
                        }

                        if (((CheckinNode)First)._bagsQueue.Count > 0)
                        {
                            current = First;
                            check   = false;
                        }


                        break;
                    }

                    case ConveyorNode NextNode when current is ConveyorNode conveyorNode:    //err 1
                    {
                        if (!conveyorNode.IsEmpty() && NextNode.IsEmpty())
                        {
                            if (NextNode.IsFull == false)
                            {
                                NextNode.PushBagToConveyorBelt(conveyorNode
                                                               .RemoveBagFromConveyorBelt());
                            }
                        }

                        break;
                    }
                    }
                    if (check)
                    {
                        current = current.Next;
                    }
                }
            }
            else
            {
                throw new Exception("no simulation made");
            }
        }