コード例 #1
0
ファイル: Model.cs プロジェクト: Eugene-El/Modelling_LR1
        public Model(
            AbstractGenerator sourceAGenerator,
            AbstractGenerator sourceBGenerator,
            AbstractGenerator serverAGenerator,
            AbstractGenerator serverBGenerator,
            ModelTime maxTime)
        {
            _time   = new ModelTime();
            MaxTime = maxTime;

            Source = new Source(ref _time, sourceAGenerator, sourceBGenerator);
            Drain  = new Drain(ref _time);

            Queue  = new Queue(ref _time);
            Server = new Server(ref _time, serverAGenerator, serverBGenerator);
        }
コード例 #2
0
ファイル: Model.cs プロジェクト: Eugene-El/Modelling_LR1
        public void Run()
        {
            while (Time <= MaxTime)
            {
                var min = Min(Source.NextAGenerationTime,
                              Source.NextBGenerationTime,
                              Server.IsNextReleaseTime && !Server.IsFree ? Server.NextReleaseTime : MaxTime);

                if (min == MaxTime)
                {
                    break;
                }
                Time.Time = min.Time;

                if (Server.IsNextReleaseTime && !Server.IsFree && min == Server.NextReleaseTime)
                {
                    var tran = Server.Leave();
                    Drain.DrainTransact(tran);

                    if (!Queue.Empty)
                    {
                        Server.Enter(Queue.Leave());
                    }
                }
                else
                {
                    var tran = Source.Get();
                    Queue.Enter(tran);

                    if (Server.IsFree)
                    {
                        Server.Enter(Queue.Leave());
                    }
                }
            }
        }