コード例 #1
0
ファイル: MovieRenege.cs プロジェクト: stuarthillary/Dessert
        public static void Run()
        {
            // Sets up and starts simulation
            Console.WriteLine("Movie renege");
            _env = Sim.Environment(RandomSeed);

            // Creates movie theater
            var counter = Sim.Resource(_env, 1);
            var titles  = new[] { ".NET Unchained", "Kill Process", "Pulp Implementation" };
            var movies  = new List <MovieInfo>(titles.Length);

            movies.AddRange(titles.Select(t => new MovieInfo(t, _env.Event())));
            _theater = new Theater(counter, movies);

            // Starts process and simulates
            _env.Process(CustomerArrivals());
            _env.Run(until: SimTime);

            // Analysis and results
            foreach (var movie in movies.Where(m => m.SoldOut.Succeeded))
            {
                Console.WriteLine("Movie \"{0}\" sold out {1:.0} minutes after ticket counter opening.", movie.Title,
                                  movie.WhenSoldOut);
                Console.WriteLine("  Number of people leaving queue when film sold out: {0}", movie.RenegerCount);
            }
        }
コード例 #2
0
        public Client(SimEnvironment env, G g, int id) : base(env, g)
        {
            _id = id;
            for (var i = 1; i < G.MachineCount; ++i)
            {
                var index = (i + id) % G.MachineCount;
                _peers[i - 1] = new ServerInfo(index);
            }

            _packetConstructed = env.Event();
        }
コード例 #3
0
        static IEnumerable <SimEvent> Process(SimEnvironment env)
        {
            var ev = env.Event <string>();

            env.Process(EventFailer(ev));
            yield return(ev);

            if (ev.Failed)
            {
                Console.WriteLine(ev.Value);
            }
        }
コード例 #4
0
        static IEnumerable <SimEvent> Proc(SimEnvironment env)
        {
            var ev1 = env.Event();

            env.Process(DoSucceed(env, ev1));
            yield return(ev1);

            if (ev1.Succeeded)
            {
                Console.WriteLine(ev1.Value);
            }

            var ev2 = env.Event();

            env.Process(DoFail(env, ev2));
            yield return(ev2);

            if (ev2.Failed)
            {
                Console.WriteLine(ev2.Value);
            }
        }
コード例 #5
0
        public SimEvents Life(SimEnvironment env)
        {
            LifeEvent = env.Event();
            Message   = "Drat! Some " + Name + " survived Federation attack!";
            while (true)
            {
                yield return(LifeEvent);

                Lives -= 1;
                Damage = 0;
                if (Lives > 0)
                {
                    continue;
                }
                Message = string.Format("{0} wiped out by Federation at {1}", Name, env.Now);
                //sim.Stop();
            }
        }