Ejemplo n.º 1
0
        public static void Run()
        {
            var env = Sim.Environment(21);

            env.Process(PersonGenerator(env));
            env.Run(SimTime);
        }
Ejemplo n.º 2
0
        public static void Main()
        {
            var env = Sim.Environment();

            env.Process(Execute(env, 33));
            env.Run(until: 100);
        }
Ejemplo n.º 3
0
        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);
            }
        }
Ejemplo n.º 4
0
        public static void Run()
        {
            var env = Sim.Environment(21);

            env.Process(Machine(env));
            env.Run(SimTime);
        }
Ejemplo n.º 5
0
 public virtual void SetUp()
 {
     Env = Sim.Environment();
     Assert.IsNotNull(Env);
     Assert.IsInstanceOf(typeof(SimEnvironment), Env);
     Assert.AreEqual(0, Env.Now);
 }
Ejemplo n.º 6
0
        public static void Run()
        {
            var env = Sim.Environment();

            env.Process(Process(env));
            env.Run();
        }
Ejemplo n.º 7
0
        public static void Run()
        {
            var env = Sim.Environment(21);

            env.Process(PastaCook(env));
            env.Run(SimTime);
        }
Ejemplo n.º 8
0
        public static void Run()
        {
            // Sets up and starts the simulation.
            Console.WriteLine("Process communication");
            var env = Sim.Environment();

            // For one-to-one or many-to-one type pipes, use Resources.Store.
            var pipe = Sim.Store <Message>(env);

            env.Process(MessageGenerator("Generator A", env, pipe));
            env.Process(MessageConsumer("Consumer A", env, pipe));

            Console.WriteLine();
            Console.WriteLine("One-to-one pipe communication");
            Console.WriteLine();
            env.Run(until: SimTime);

            // For one-to many, instead, use BroadcastPipe.
            // (Note: it could also be used for one-to-one, many-to-one or many-to-many)
            env = Sim.Environment();
            var bcPipe = new BroadcastPipe <Message>(env);

            env.Process(MessageGenerator("Generator A", env, bcPipe));
            env.Process(MessageConsumer("Consumer A", env, bcPipe.OutputConn()));
            env.Process(MessageConsumer("Consumer B", env, bcPipe.OutputConn()));

            Console.WriteLine();
            Console.WriteLine("One-to-many pipe communication");
            Console.WriteLine();
            env.Run(until: SimTime);
        }
Ejemplo n.º 9
0
        public void Environment_ShouldNotChangeDefaultRealTimeOptionsAfterCreation_WithSeed_WallClock()
        {
            var env = Sim.Environment(21);

            Assert.That(env.RealTime.Enabled, Is.False);
            Assert.That(env.RealTime.Locked, Is.True);
            env.RealTime.WallClock = new MockClock();
        }
Ejemplo n.º 10
0
        public void Environment_ShouldNotChangeDefaultRealTimeOptionsAfterCreation_WithSeed_ScalingFactor()
        {
            var env = Sim.Environment(21);

            Assert.That(env.RealTime.Enabled, Is.False);
            Assert.That(env.RealTime.Locked, Is.True);
            env.RealTime.ScalingFactor = 3.0;
        }
Ejemplo n.º 11
0
        public static void Run()
        {
            var sim = Sim.Environment();
            var car = new Car(sim);

            sim.Process(Driver(sim, car));
            sim.Run(until: 15);
        }
Ejemplo n.º 12
0
        public static void Run()
        {
            var env = Sim.Environment();

            env.DelayedProcess(Process(env, 'A'), 7);
            env.Process(Process(env, 'B'));
            env.Run();
        }
Ejemplo n.º 13
0
        public static void Run()
        {
            var env   = Sim.Environment(21);
            var train = env.Process(Train(env));

            env.Process(EmergencyBrake(env, train));
            env.Run();
        }
Ejemplo n.º 14
0
        // Expected output:
        // Hello World simulation :)
        // Hello World at 2.1!
        // Hello World at 4.2!
        // Hello World at 6.3!
        // Hello World at 8.4!
        public static void Run()
        {
            Console.WriteLine("Hello World simulation :)");
            var env = Sim.Environment();

            env.Process(SayHello(env));
            env.Run(10);
        }
Ejemplo n.º 15
0
        public static void Run()
        {
            var env = Sim.Environment();

            env.Process(Clock(env, "fast", 0.5));
            env.Process(Clock(env, "slow", 1.0));
            env.Run(until: 2);
        }
Ejemplo n.º 16
0
        // Expected output:
        // Starting simulation
        // Here I am at the shop Marta
        // I just bought something Marta
        // I just bought something Marta
        // I just bought something Marta
        // I just bought something Marta
        // All I have left is 60 I am going home Marta
        // Current time is 30
        public static void Main()
        {
            var env = Sim.Environment();

            env.DelayedProcess(Buy(env, "Marta", 100), delay: 10);
            Console.WriteLine("Starting simulation");
            env.Run(until: 100);
            Console.WriteLine("Current time is {0}", env.Now);
        }
Ejemplo n.º 17
0
        // Expected output:
        // Breakdown Bus at 300
        // Bus repaired at 320
        // Breakdown Bus at 620
        // Bus repaired at 640
        // Breakdown Bus at 940
        // Bus repaired at 960
        // Bus has arrived at 1060
        // Dessert: No more events at time 1260
        public static void Main()
        {
            var env = Sim.Environment();
            var bus = env.Process(OperateBus(env, repairDuration: 20, tripLength: 1000));

            _breakBus = env.Process(BreakBus(env, bus, interval: 300));
            env.Run(until: 4000);
            Console.WriteLine("Dessert: No more events at time {0}", env.Now);
        }
Ejemplo n.º 18
0
        public static void Run()
        {
            var env = Sim.Environment(seed: 42);
            var rec = Sim.Tally(env);

            env.Process(Spawner(env, rec));
            env.Run(2 * 60);
            Console.WriteLine("Total clients: {0}", rec.Total());
            Console.WriteLine("Average wait: {0:.0}", rec.Mean());
        }
Ejemplo n.º 19
0
        // Expected output:
        // Starting simulation
        // 0 1 Starting
        // 6 2 Starting
        // 100 1 Arrived
        // 106 2 Arrived
        // Current time is 106
        public static void Run()
        {
            var env = Sim.Environment();

            env.Process(Go(env, 1));
            env.DelayedProcess(Go(env, 2), delay: 6);
            Console.WriteLine("Starting simulation");
            env.Run(until: 200);
            Console.WriteLine("Current time is {0}", env.Now);
        }
Ejemplo n.º 20
0
        public static void Run()
        {
            // Setup and start the simulation
            Console.WriteLine("Bank renege");
            var env = Sim.Environment(RandomSeed);

            // Start processes and simulate
            var counter = Sim.Resource(env, capacity: 1);

            env.Process(Source(env, NewCustomers, IntervalCustomers, counter));
            env.Run();
        }
        public static void Run()
        {
            const int count = 10;
            var       env   = Sim.Environment();
            var       store = Sim.Store <int>(env);

            for (var i = 0; i < count; ++i)
            {
                env.Process(Producer(env, store, i));
                env.Process(Consumer(store));
            }
            env.Run();
        }
Ejemplo n.º 22
0
        /// <summary>
        ///   Sets up and starts the simulation.
        /// </summary>
        public static void Run()
        {
            Console.WriteLine("Gas Station refueling");

            // Creates the environment and starts processes.
            var env        = Sim.Environment(RandomSeed);
            var gasStation = Sim.Resource(env, 2);
            var fuelPump   = Sim.Container(env, GasStationSize, level: GasStationSize);

            env.Process(GasStationControl(env, fuelPump));
            env.Process(CarGenerator(env, gasStation, fuelPump));

            // Run!
            env.Run(until: SimTime);
        }
Ejemplo n.º 23
0
        public static void Main()
        {
            var       sim      = Sim.Environment();
            const int gameOver = 100;
            // Creates a Player object named "Romulans"
            var target = new Player(lives: 3, name: "Romulans");

            sim.Process(target.Life(sim));
            // Creates a Federation object
            var shooter = new Federation();

            sim.Process(shooter.Fight(sim, target));
            sim.Run(until: gameOver);
            Console.WriteLine(target.Message);
        }
Ejemplo n.º 24
0
        public static void Run()
        {
            var       env      = Sim.Environment(seed: 21);
            const int capacity = 10;
            var       store    = Sim.Store <int>(env, capacity, WaitPolicy.FIFO, WaitPolicy.FIFO, WaitPolicy.Random);

            for (var i = 0; i < capacity; ++i)
            {
                store.Put(i);
            }
            for (var i = 0; i < capacity; ++i)
            {
                env.Process(Getter(store, (char)('A' + i)));
            }
            env.Run();
        }
Ejemplo n.º 25
0
        public static void Run()
        {
            // We create the environment into which
            // our first simulation will run.
            var env = Sim.Environment(RandomSeed);

            // We start two "Person" processes,
            // which will have a random name picked from Names.
            env.Process(Person(env, env.Random.Choice(Names)));
            env.DelayedProcess(Person(env, env.Random.Choice(Names)), delay: 3);

            // After that, we finally start our simulation.
            // We expect an output similar to the following:
            // Hi, I'm Pino and I will wait for 5 minutes!
            // Hi, I'm Dino and I will wait for 5 minutes!
            // Ok, Pino's wait has finished at 5. Bye :)
            // Ok, Dino's wait has finished at 8. Bye :)
            env.Run();
        }
Ejemplo n.º 26
0
        static void RunSimulation(int simId, int h)
        {
            var seed = (simId + 1) * (h + 1) + Environment.TickCount;
            var env  = Sim.Environment(seed);
            var g    = new G();

            // Processes creation (and activation)
            // 1. The switch
            g.Switch = new Switch(env, g);
            env.Process(g.Switch.Run());
            g.Switch.SetLogger("SWITCH");
            for (var i = 0; i < G.MachineCount; ++i)
            {
                // 2. The server operative systems
                var svOS = new ServerOS(env, g, i);
                env.Process(svOS.Run());
                svOS.SetLogger("SERVER_OS_" + i);
                g.ServerOSes[i] = svOS;
                // 3. The server processes
                var sv = new Server(env, g, i);
                env.Process(sv.Run());
                sv.SetLogger("SERVER_" + i);
                g.Servers[i] = sv;
                // 4. The client operative systems
                var clOS = new ClientOS(env, g, i);
                env.Process(clOS.Run());
                clOS.SetLogger("CLIENT_OS_" + i);
                g.ClientOSes[i] = clOS;
                // 5. The client processes
                var cl = new Client(env, g, i);
                env.Process(cl.Run());
                cl.SetLogger("CLIENT_" + i);
                g.Clients[i] = cl;
            }
            // 6. The memory recorder
            env.Process(MemoryRecorder.Run(env, g.Stats));

            Console.WriteLine("Starting simulation {0} (h = {1})", simId, h);
            StorePackets(g.Servers);
            env.Run(until: G.MaxSimTime);
            Debug.Assert(env.Now >= G.MaxSimTime, "Ended prematurely!");
            PrintStats(g.Stats, simId, h);
        }
        public static void Run()
        {
            // We specify the seed in order to have fixed results in all examples; however, in a
            // production environment, it should be different among all simulations, so that each
            // simulations produces unique results.
            const int seed = 21;
            var       env  = Sim.Environment(seed);

            // Here we record values using a "tally", which keeps tracks only of results (median,
            // mode, mean, ...) and not of the data itself. Tallies have a very low memory footprint.
            var aPressureRecorder    = Sim.Tally(env);
            var aTemperatureRecorder = Sim.Tally(env);

            env.Process(Machine(env, 'A', aPressureRecorder, aTemperatureRecorder));

            // Here we record values using a "monitor", which keeps tracks of results (median, mode,
            // mean, ...) and also of the observed data. Of course, monitors use more memory than tallies.
            var bPressureRecorder    = Sim.Monitor(env);
            var bTemperatureRecorder = Sim.Monitor(env);

            env.Process(Machine(env, 'B', bPressureRecorder, bTemperatureRecorder));

            // Run the simulation.
            env.Run(SimTime);

            Console.WriteLine();
            Console.WriteLine($"Machine A average pressure: {aPressureRecorder.Mean():.00} bar");
            Console.WriteLine($"Machine A average temperature: {aTemperatureRecorder.Mean():.00} °F");
            Console.WriteLine();
            Console.WriteLine($"Machine B average pressure: {bPressureRecorder.Mean():.00} bar");
            Console.WriteLine($"Machine B average temperature: {bTemperatureRecorder.Mean():.00} °F");

            // Since we used two monitors for machine B, we can also print the recorded data.
            var pressureValues    = string.Join(", ", bPressureRecorder.Samples.Select(s => s.Sample.ToString(".00")));
            var temperatureValues = string.Join(", ", bTemperatureRecorder.Samples.Select(s => s.Sample.ToString()));

            Console.WriteLine();
            Console.WriteLine($"Machine B pressure values: {pressureValues}");
            Console.WriteLine($"Machine B temperature values: {temperatureValues}");
        }
Ejemplo n.º 28
0
        public static void Run()
        {
            // We create the environment into which
            // our first simulation will run.
            var env = Sim.Environment(RandomSeed);

            // The postOffice can be represented as a resource,
            // whose "capacity" is given by the number of employees
            // the simulated post office has.
            var postOffice = Sim.Resource(env, EmployeeCount);

            // We start the "PersonSpawner" processes,
            // which will start new "Person" processes at random intervals.
            env.Process(PersonSpawner(env, postOffice));

            // After that, we finally start our simulation.
            // We expect an output similar to the following:
            // Hi, I'm Pino and I entered the office at 0,00
            // Finally it's Pino's turn! I waited 0,00 minutes
            // Pino's job will take 1,43 minutes
            // Ok, Pino leaves the office at 1,43. Bye :)
            // Hi, I'm Pino and I entered the office at 2,86
            // Finally it's Pino's turn! I waited 0,00 minutes
            // Pino's job will take 1,60 minutes
            // Hi, I'm Bobb and I entered the office at 3,50
            // Finally it's Bobb's turn! I waited 0,00 minutes
            // Bobb's job will take 1,28 minutes
            // Ok, Pino leaves the office at 4,46. Bye :)
            // Ok, Bobb leaves the office at 4,78. Bye :)
            // Hi, I'm Pino and I entered the office at 9,49
            // Finally it's Pino's turn! I waited 0,00 minutes
            // Pino's job will take 5,48 minutes
            // Hi, I'm Dino and I entered the office at 9,67
            // Finally it's Dino's turn! I waited 0,00 minutes
            // Dino's job will take 0,64 minutes
            // Ok, Dino leaves the office at 10,31. Bye :)
            env.Run(until: 20);
        }