public void ConnectNodes(IList <IChainLink> nodes, IEnumerable <NodeCreationData> nodesData)
        {
            var checkInDispatcher = GetNodesOfType <ICheckInDispatcher>(nodes).First();
            var aaDispatcher      = GetNodesOfType <IAADispatcher>(nodes).First();
            var bagCollector      = GetNodesOfType <IBagCollector>(nodes).First();

            checkInDispatcher.SetCheckIns(GetNodesOfType <ICheckInDesk>(nodes).ToList());
            aaDispatcher.SetUpGates(GetNodesOfType <Aa>(nodes).ToList());

            nodesData = nodesData.OrderBy(x => x.NextNodes?.Count ?? 0);

            foreach (var nodeCreationData in nodesData)
            {
                var currentNode = nodes.FirstOrDefault(n => n.NodeId == nodeCreationData.Id);
                var nextNodes   = nodes?.Where(n => nodeCreationData.NextNodes?
                                               .Select(nn => nn.Key.Id)
                                               .Contains(n.NodeId) ?? false) ?? new List <IChainLink>();

                //If current node is end node => attach the bagCollector
                if (currentNode is IPickUpArea || currentNode is IAsc || currentNode is IAa)
                {
                    ((IProcessingNode)currentNode).AddSuccessor(bagCollector);
                }

                //Set the successor nodes
                foreach (var nextNode in nextNodes)
                {
                    if (nextNode is IManyToOneConveyor manyToOneConveyor)
                    {
                        var connector = _chainLinkFactory.CreateConveyorConnector();
                        var index     = nodeCreationData.NextNodes[nodeCreationData.NextNodes.Keys.FirstOrDefault(k => k.Id == manyToOneConveyor.NodeId)];

                        if (currentNode is ISingleSuccessor single)
                        {
                            single.SetSuccessor(connector);
                        }
                        else if (currentNode is IMultiSuccessor multi)
                        {
                            multi.AddSuccessor(connector);
                        }

                        connector.SetNextNode(manyToOneConveyor, index ?? 0);
                    }
                    else
                    {
                        if (currentNode is ISingleSuccessor single)
                        {
                            single.SetSuccessor(nextNode);
                        }
                        else if (currentNode is IMultiSuccessor multi)
                        {
                            multi.AddSuccessor(nextNode);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        public void Run(SimulationSettings settings)
        {
            _chainLinkFactory.SetSettings(settings);
            _timerService.SetSettings(settings);

            var checkIn = _chainLinkFactory.CreateCheckInDesk();
            var checkInToConveyorConnector = _chainLinkFactory.CreateConveyorConnector();
            var checkInToPsc = _chainLinkFactory.CreateManyToOneConveyor(settings.ConveyorSettingsCheckInToPsc[0].Length);
            var psc          = _chainLinkFactory.CreatePsc();
            var PscToMpa     = _chainLinkFactory.CreateOneToOneConveyor(settings.ConveyorSettingsPscToMpa[0].Length);
            var PscToAsc     = _chainLinkFactory.CreateOneToOneConveyor(settings.ConveyorSettingsPscToAsc[0].Length);
            var asc          = _chainLinkFactory.CreateAsc();
            var ascToMpa     = _chainLinkFactory.CreateOneToOneConveyor(settings.ConveyorSettingsAscToMpu[0].Length);
            var mpa          = _chainLinkFactory.CreateMpa();
            var bsu          = _chainLinkFactory.CreateBsu();
            var mpaToBsu     = _chainLinkFactory.CreateOneToOneConveyor(10);         //Implement conveyorSettings
            var bsuToMpa     = _chainLinkFactory.CreateOneToOneConveyor(10);         //Implement conveyorSettings
            var MpaToAA      = _chainLinkFactory.CreateOneToOneConveyor(settings.ConveyorSettingsMpaToAa[0].Length);
            var aa           = _chainLinkFactory.CreateAa();
            var pua          = _chainLinkFactory.CreatePua();

            //EndNodes
            var checkInDispatcher = _chainLinkFactory.CreateCheckInDispatcher();
            var bagCollector      = _chainLinkFactory.CreateBagCollector();

            //Linking
            checkInDispatcher.SetCheckIns(new List <ICheckInDesk> {
                checkIn
            });

            checkIn.AddSuccessor(checkInToConveyorConnector);
            //checkIn1.AddSuccessor(checkIn1ToConveyorConnector);
            //checkIn2.AddSuccessor(checkIn2ToConveyorConnector);
            checkInToConveyorConnector.SetNextNode(checkInToPsc, 0);
            checkInToPsc.SetSuccessor(psc);
            //checkIn1ToConveyorConnector.SetNextNode(checkIn2ToPsc, 1);
            //checkIn2ToConveyorConnector.SetNextNode(checkIn2ToPsc, 2);

            // checkInToPsc.SetSuccessor(psc);

            //Transporting nodes
            mpaToBsu.SetSuccessor(bsu);
            PscToMpa.SetSuccessor(mpa);
            PscToAsc.SetSuccessor(asc);
            ascToMpa.SetSuccessor(mpa);
            MpaToAA.SetSuccessor(aa);
            bsuToMpa.SetSuccessor(mpa);

            //Processing and complex nodes
            psc.AddSuccessor(PscToMpa);
            psc.AddSuccessor(PscToAsc);
            asc.AddSuccessor(ascToMpa);
            asc.AddSuccessor(bagCollector);
            aa.AddSuccessor(bagCollector);
            mpa.AddSuccessor(MpaToAA);
            mpa.AddSuccessor(mpaToBsu);
            bsu.SetSuccessor(bsuToMpa);
            aa.AddSuccessor(bagCollector);

            //Starting
            _timerService.RunNewTimer();
            checkInToPsc.Start();

            PscToMpa.Start();
            MpaToAA.Start();
            mpaToBsu.Start();
            bsuToMpa.Start();
            checkInDispatcher.Start();
        }