public OnlineExecutionContext Execute(OnlineChain onlineChainOnFirst, OnlineChain onlineChainOnSecond,
                                              HashSet <int> processedDetailsOnFirst, HashSet <int> processedDetailsOnSecond)
        {
            var context = new OnlineExecutionContext();

            IOnlineChainNode currentDetailOnFirst  = null;
            IOnlineChainNode currentDetailOnSecond = null;

            var timeFromMachinesStart = 0.0;
            var time1 = 0.0;
            var time2 = 0.0;

            var isFirstDetail = true;

            var nodeOnFirstMachine  = onlineChainOnFirst.First;
            var nodeOnSecondMachine = onlineChainOnSecond.First;

            var hasDetailOnFirst  = nodeOnFirstMachine != null;
            var hasDetailOnSecond = nodeOnSecondMachine != null;

            // details are on two machines
            while (hasDetailOnFirst && hasDetailOnSecond ||
                   time1 > time2 && hasDetailOnSecond ||
                   time2 > time1 && hasDetailOnFirst)
            {
                // time1 equal to time2
                if (Math.Abs(time1 - time2) < 0.001)
                {
                    if (hasDetailOnFirst)
                    {
                        ProcessDetailOnMachine(
                            ref currentDetailOnFirst,
                            processedDetailsOnFirst,
                            processedDetailsOnSecond,
                            ref nodeOnFirstMachine,
                            ref nodeOnSecondMachine,
                            timeFromMachinesStart,
                            onlineChainOnFirst,
                            onlineChainOnSecond,
                            ref time1,
                            out hasDetailOnFirst,
                            isFirstDetail,
                            context);
                    }


                    //if (nodeOnSecondMachine?.List == null)
                    //{
                    //    if (isFirstDetail)
                    //        nodeOnSecondMachine = experimentInfo.OnlineChainOnSecondMachine.First;
                    //}

                    if (hasDetailOnSecond)
                    {
                        ProcessDetailOnMachine(
                            ref currentDetailOnSecond,
                            processedDetailsOnSecond,
                            processedDetailsOnFirst,
                            ref nodeOnSecondMachine,
                            ref nodeOnFirstMachine,
                            timeFromMachinesStart,
                            onlineChainOnSecond,
                            onlineChainOnFirst,
                            ref time2,
                            out hasDetailOnSecond,
                            isFirstDetail,
                            context);
                    }
                }
                else if (time1 < time2)
                {
                    ProcessDetailOnMachine(
                        ref currentDetailOnFirst,
                        processedDetailsOnFirst,
                        processedDetailsOnSecond,
                        ref nodeOnFirstMachine,
                        ref nodeOnSecondMachine,
                        timeFromMachinesStart,
                        onlineChainOnFirst,
                        onlineChainOnSecond,
                        ref time1,
                        out hasDetailOnFirst,
                        isFirstDetail,
                        context);
                }
                else
                {
                    ProcessDetailOnMachine(
                        ref currentDetailOnSecond,
                        processedDetailsOnSecond,
                        processedDetailsOnFirst,
                        ref nodeOnSecondMachine,
                        ref nodeOnFirstMachine,
                        timeFromMachinesStart,
                        onlineChainOnSecond,
                        onlineChainOnFirst,
                        ref time2,
                        out hasDetailOnSecond,
                        isFirstDetail,
                        context);
                }

                timeFromMachinesStart = Math.Min(time1, time2);

                isFirstDetail = false;
            }

            // details only on first machines
            if (hasDetailOnFirst)
            {
                for (var node = nodeOnFirstMachine; node != null; node = node.Next)
                {
                    if (node.Value is Detail detail)
                    {
                        time1 += detail.Time.P;
                    }
                    else
                    {
                        throw new InvalidOperationException(
                                  "There can be no conflicts and downtimes when one of machine finished work");
                    }
                }
            }
            else
            {
                // details only on second machine
                for (var node = nodeOnSecondMachine; node != null; node = node.Next)
                {
                    if (node.Value is Detail detail)
                    {
                        time2 += detail.Time.P;
                    }
                    else
                    {
                        throw new InvalidOperationException(
                                  "There can be no conflicts and downtimes when one of machine finished work");
                    }
                }
            }

            timeFromMachinesStart = Math.Max(time1, time2);

            context.TimeFromMachinesStart = timeFromMachinesStart;
            context.Time1 = time1;
            context.Time2 = time2;

            return(context);
        }
Beispiel #2
0
 public void GenerateP(IOnlineChainNode node) => node.GenerateP(_randomizeService);