Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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());
                    }
                }
            }
        }