private IEnumerable<Event> Customer(Environment env, string name, Resource counter, TimeSpan meanTimeInBank) { var arrive = env.Now; env.Log("{0} {1}: Here I am", arrive, name); using (var req = counter.Request()) { // Wait for the counter or abort at the end of our tether var timeout = env.TimeoutUniform(MinPatience, MaxPatience); yield return req | timeout; var wait = env.Now - arrive; if (req.IsProcessed) { // We got the counter env.Log("{0} {1}: waited {2}", env.Now, name, wait); yield return env.TimeoutExponential(meanTimeInBank); env.Log("{0} {1}: Finished", env.Now, name); } else { // We reneged env.Log("{0} {1}: RENEGED after {2}", env.Now, name, wait); } } }
private IEnumerable<Event> Car(string name, Environment env, Resource gasStation, Container fuelPump) { /* * A car arrives at the gas station for refueling. * * It requests one of the gas station's fuel pumps and tries to get the * desired amount of gas from it. If the stations reservoir is * depleted, the car has to wait for the tank truck to arrive. */ var fuelTankLevel = env.RandUniform(MinFuelTankLevel, MaxFuelTankLevel + 1); env.Log("{0} arriving at gas station at {1}", name, env.Now); using (var req = gasStation.Request()) { var start = env.Now; // Request one of the gas pumps yield return req; // Get the required amount of fuel var litersRequired = FuelTankSize - fuelTankLevel; yield return fuelPump.Get(litersRequired); // The "actual" refueling process takes some time yield return env.Timeout(TimeSpan.FromSeconds(litersRequired / RefuelingSpeed)); env.Log("{0} finished refueling in {1} seconds.", name, (env.Now - start).TotalSeconds); } }
public void Simulate() { var env = new Environment(TimeSpan.FromMinutes(1)); env.Log("== Steel Factory =="); var crane = new Resource(env, 1); env.Process(Cast(env, crane, "CC1", new[] { new Slab(4), new Slab(4), new Slab(8), new Slab(3), new Slab(2) })); env.Process(Cast(env, crane, "CC2", new[] { new Slab(2), new Slab(3), new Slab(3), new Slab(4), new Slab(3) })); env.Run(TimeSpan.FromMinutes(100)); }
private IEnumerable<Event> Cast(Environment env, Resource crane, string name, IEnumerable<Slab> castQueue) { foreach (var slab in castQueue) { yield return env.TimeoutD(slab.CastTime); env.Log("Caster {0} finished at {1}", name, env.Now); var token = crane.Request(); yield return token; env.Process(Transport(env, crane, token, name)); } }
private static readonly TimeSpan MinPatience = TimeSpan.FromMinutes(1); // Min. customer patience #endregion Fields #region Methods public void Simulate(int rseed = 41) { // Setup and start the simulation var start = new DateTime(2014, 2, 1); // Create an environment and start the setup process var env = new Environment(start, 41); env.Log("== Bank renege =="); var counter = new Resource(env, capacity: 1); env.Process(Source(env, counter)); env.Run(); }
public void Simulate(int rseed = 42) { // Setup and start the simulation var env = new Environment(rseed, TimeSpan.FromSeconds(1)); env.Log("== Process communication =="); var pipe = new Store(env); env.Process(MessageGenerator("Generator A", env, pipe)); env.Process(MessageConsumer("Consumer A", env, pipe)); env.Run(TimeSpan.FromSeconds(100)); }
public void Simulate() { queueSize = 0; env = new Environment(); server = new Resource(env, capacity: 1); statistics = new ContinuousStatistics(env); env.Log("== m/m/1 queuing system =="); env.Process(Source()); env.Run(TimeSpan.FromDays(180)); Console.WriteLine("QueueSize Statistics:"); Console.WriteLine("Min: {0}; Max: {1}; Mean: {2:F2}; StdDev: {3:F2}", statistics.Min, statistics.Max, statistics.Mean, statistics.StdDev); }
public void Simulate() { completedOrders = 0; env = new Environment(); env.Log("== Kanban controlled production system =="); kanban = new Resource(env, capacity: 15); server = new Resource(env, capacity: 1); stockStat = new ContinuousStatistics(env); env.Process(Source()); env.Run(TimeSpan.FromDays(180)); Console.WriteLine("Stock: {0} ; {1:F3}±{2:F3} ; {3} (Min;Mean±StdDev;Max) kanbans ", stockStat.Min, stockStat.Mean, stockStat.StdDev, stockStat.Max); Console.WriteLine("Produced kanbans: {0:N0}", completedOrders); }
private static readonly TimeSpan TankTruckTime = TimeSpan.FromMinutes(10); // Minutes it takes the tank truck to arrive #endregion Fields #region Methods public void Simulate(int rseed = RandomSeed) { // Setup and start the simulation // Create environment and start processes var env = new Environment(rseed); env.Log("== Gas Station refuelling =="); var gasStation = new Resource(env, 2); var fuelPump = new Container(env, GasStationSize, GasStationSize); env.Process(GasStationControl(env, fuelPump)); env.Process(CarGenerator(env, gasStation, fuelPump)); // Execute! env.Run(SimTime); }
private IEnumerable<Event> MessageConsumer(string name, Environment env, Store inPipe) { // A process which consumes messages. while (true) { // Get event for message pipe var get = inPipe.Get(); yield return get; var msg = (object[])get.Value; if (((DateTime)msg[0]) < env.Now) { // if message was already put into pipe, then // message_consumer was late getting to it. Depending on what // is being modeled this, may, or may not have some // significance env.Log("LATE Getting Message: at time {0}: {1} received message: {2}", env.Now, name, msg[1]); } else { // message_consumer is synchronized with message_generator env.Log("at time {0}: {1} received message: {2}.", env.Now, name, msg[1]); } // Process does some other work, which may result in missing messages yield return env.TimeoutUniformD(4, 9); } }
private IEnumerable<Event> TankTruck(Environment env, Container fuelPump) { // Arrives at the gas station after a certain delay and refuels it. yield return env.Timeout(TankTruckTime); env.Log("Tank truck arriving at time {0}", env.Now); var amount = fuelPump.Capacity - fuelPump.Level; env.Log("Tank truck refuelling {0} liters.", amount); yield return fuelPump.Put(amount); }
private IEnumerable<Event> GasStationControl(Environment env, Container fuelPump) { /* * Periodically check the level of the *fuel_pump* and call the tank * truck if the level falls below a threshold. */ while (true) { if (fuelPump.Level / fuelPump.Capacity * 100 < Threshold) { // We need to call the tank truck now! env.Log("Calling tank truck at {0}", env.Now); // Wait for the tank truck to arrive and refuel the station yield return env.Process(TankTruck(env, fuelPump)); } yield return env.Timeout(TimeSpan.FromSeconds(10)); // Check every 10 seconds } }
private IEnumerable<Event> Transport(Environment env, Resource crane, Request token, string caster) { env.Log("Crane transporting from caster {0} at {1}", caster, env.Now); yield return env.TimeoutD(4); crane.Release(token); }
private IEnumerable<Event> FilterStoreProducer(Environment env, FilterStore sto) { while (true) { yield return env.Timeout(TimeSpan.FromSeconds(4)); yield return sto.Put(FilterStoreObjA); env.Log("{0}: Produce A", env.Now.Second); yield return env.Timeout(TimeSpan.FromSeconds(2)); yield return sto.Put(FilterStoreObjB); env.Log("{0}: Produce B", env.Now.Second); } }
private IEnumerable<Event> FilterStoreConsumerB(Environment env, FilterStore sto) { while (true) { yield return sto.Get(x => x == FilterStoreObjB); env.Log("{0}: Consume B", env.Now.Second); yield return env.Timeout(TimeSpan.FromSeconds(3)); } }