public void TestTriggeredTimeout() { var env = new Environment(); env.Process(TestTriggeredTimeout(env)); env.Run(); Assert.AreEqual(2, env.NowD); }
public void TestErrorAndInterruptedJoin() { var executed = false; var env = new Environment(new DateTime(1970, 1, 1, 0, 0, 0)); env.Process(ErrorAndInterruptedJoinParent(env, () => executed = true)); env.Run(); Assert.IsTrue(executed); }
public void TestGetState() { // A process is alive until it's generator has not terminated. var env = new Environment(); var procA = env.Process(GetStatePemA(env)); env.Process(GetStatePemB(env, procA)); env.Run(); }
public void TestExit() { // Processes can set a return value var executed = false; var env = new Environment(new DateTime(1970, 1, 1, 0, 0, 0)); env.Process(ExitParent(env, () => executed = true)); env.Run(); Assert.IsTrue(executed); }
public void Simulate() { var env = new Environment(randomSeed: 41); var packer = new Resource(env, 1); env.Process(Machine(env, packer)); env.Process(Machine(env, packer)); env.Run(TimeSpan.FromHours(8)); Console.WriteLine("The machines were delayed for {0}", delay); }
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)); }
/// <summary> /// This method will benchmark Sim#'s performance with respect to creation /// of entities. In SimPy and also Sim# the equivalence of an entity is a /// process. This stress tests the performance of creating processes. /// </summary> static long Benchmark2(Environment env) { perf = 0; env.Process(Benchmark2Source(env)); var watch = Stopwatch.StartNew(); env.Run(terminate); watch.Stop(); return watch.ElapsedTicks; }
public void TestChildException() { // A child catches an exception and sends it to its parent. // This is the same as TestExit var executed = false; var env = new Environment(new DateTime(1970, 1, 1, 0, 0, 0)); env.Process(ChildExceptionParent(env, () => executed = true)); env.Run(); Assert.IsTrue(executed); }
public void TestEventQueueEmpty() { /*The simulation should stop if there are no more events, that means, no more active process.*/ var log = new List<string>(); var env = new Environment(); env.Process(AProcess(env, log)); env.Run(TimeSpan.FromMinutes(10)); Assert.IsTrue(log.SequenceEqual(new[] { "00", "01" })); }
public void TestAnyOfEmptyList() { var env = new Environment(); var evt = new AnyOf(env, Enumerable.Empty<Event>()); Assert.IsTrue(evt.IsTriggered); Assert.IsFalse(evt.IsProcessed); env.Run(evt); Assert.IsTrue(evt.IsProcessed); Assert.AreEqual(0, env.NowD); }
public object Invoke(Environment e, object[] args) { foreach (object o in argnames) { // FIXME e.Set(o.ToString(), e.GetObject(o.ToString())); } return e.Run(Pieces.ToArray()); // TODO: remove args from env }
public void TestFilterCallsBestCase() { var env = new Environment(); var store = new FilterStore(env, new object[] { 1, 2, 3 }, 3); var log = new List<string>(); Func<object, bool> filterLogger = o => { log.Add(string.Format("check {0}", o)); return true; }; env.Process(TestFilterCallsBestCaseProcess(store, filterLogger, log)); env.Run(); Assert.IsTrue(log.SequenceEqual(new[] { "check 1", "get 1", "check 2", "get 2", "check 3", "get 3" })); }
/// <summary> /// This method will benchmark Sim#'s performance with respect to the list /// of future events. A large number of processes that exist in the system /// stress tests the performance of operations on the event queue. /// </summary> /// <param name="n">The number of concurrent processes.</param> static long Benchmark1(Environment env, int n) { perf = 0; for (var i = 0; i < n; i++) { env.Process(Benchmark1Proc(env, n)); } var watch = Stopwatch.StartNew(); env.Run(terminate); watch.Stop(); return watch.ElapsedTicks; }
/// <summary> /// This method will benchmark Sim#'s performance with respect to /// seizing and releasing resources, a common task in DES models. /// </summary> static long Benchmark3(Environment env) { perf = 0; var res = new Resource(env, capacity: 1); env.Process(Benchmark3Proc(env, res)); env.Process(Benchmark3Proc(env, res)); var watch = Stopwatch.StartNew(); env.Run(terminate); watch.Stop(); return watch.ElapsedTicks; }
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 TestRunNegativeUntil() { /*Test passing a negative time to run.*/ var env = new Environment(); var errorThrown = false; try { env.Run(new DateTime(1969, 12, 30)); } catch (InvalidOperationException) { errorThrown = true; } Assert.IsTrue(errorThrown); }
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(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 TestRunResume() { /* Stopped simulation can be resumed. */ var env = new Environment(); var events = new List<Event>() { env.Timeout(TimeSpan.FromMinutes(5)), env.Timeout(TimeSpan.FromMinutes(10)), env.Timeout(TimeSpan.FromMinutes(15)), env.Timeout(TimeSpan.FromMinutes(20)) }; Assert.AreEqual(env.Now, new DateTime(1970, 1, 1)); Assert.AreEqual(env.Peek(), new DateTime(1970, 1, 1, 0, 5, 0)); Assert.IsFalse(events.Any(x => x.IsProcessed)); env.Run(TimeSpan.FromMinutes(10)); Assert.AreEqual(env.Now, new DateTime(1970, 1, 1, 0, 10, 0)); Assert.AreEqual(env.Peek(), new DateTime(1970, 1, 1, 0, 10, 0)); Assert.IsTrue(events[0].IsProcessed); Assert.IsFalse(events[1].IsProcessed); Assert.IsFalse(events[2].IsProcessed); env.Run(TimeSpan.FromMinutes(5)); Assert.AreEqual(env.Now, new DateTime(1970, 1, 1, 0, 15, 0)); Assert.AreEqual(env.Peek(), new DateTime(1970, 1, 1, 0, 15, 0)); Assert.IsTrue(events[0].IsProcessed); Assert.IsTrue(events[1].IsProcessed); Assert.IsFalse(events[2].IsProcessed); env.Run(TimeSpan.FromMinutes(1)); Assert.AreEqual(env.Now, new DateTime(1970, 1, 1, 0, 16, 0)); Assert.AreEqual(env.Peek(), new DateTime(1970, 1, 1, 0, 20, 0)); Assert.IsTrue(events[0].IsProcessed); Assert.IsTrue(events[1].IsProcessed); Assert.IsTrue(events[2].IsProcessed); env.Run(); Assert.AreEqual(env.Now, new DateTime(1970, 1, 1, 0, 20, 0)); Assert.AreEqual(env.Peek(), DateTime.MaxValue); }
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); }
public void TestDiscreteTimeSteps() { var start = new DateTime(2014, 4, 1); var env = new Environment(start); var log = new List<DateTime>(); env.Process(TestDiscreteTimeSteps(env, log)); env.Run(TimeSpan.FromSeconds(3)); Assert.AreEqual(3, log.Count); for (int i = 0; i < 3; i++) Assert.IsTrue(log.Contains(start + TimeSpan.FromSeconds(i))); Assert.AreEqual(3, env.ProcessedEvents); }
public void TestContainer() { var start = new DateTime(2014, 4, 2); var env = new Environment(start); var buf = new Container(env, initial: 0, capacity: 2); var log = new List<Tuple<char, DateTime>>(); env.Process(TestContainerPutter(env, buf, log)); env.Process(TestContainerGetter(env, buf, log)); env.Run(TimeSpan.FromSeconds(5)); var expected = new List<Tuple<char, int>> { Tuple.Create('p', 1), Tuple.Create('g', 1), Tuple.Create('g', 2), Tuple.Create('p', 2) }.Select(x => Tuple.Create(x.Item1, start + TimeSpan.FromSeconds(x.Item2))).ToList(); CollectionAssert.AreEqual(expected, log); }
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); }
public void TestSharedTimeout() { var start = new DateTime(2014, 4, 1); var env = new Environment(start); var timeout = env.Timeout(TimeSpan.FromSeconds(1)); var log = new Dictionary<int, DateTime>(); for (int i = 0; i < 3; i++) env.Process(TestSharedTimeout(env, timeout, i, log)); env.Run(); Assert.AreEqual(3, log.Count); foreach (var l in log.Values) Assert.AreEqual(start + TimeSpan.FromSeconds(1), l); }
public void TestFilterCallsWorstCase() { var env = new Environment(); var store = new FilterStore(env, 4); var log = new List<string>(); Func<object, bool> filterLogger = o => { log.Add(string.Format("check {0}", o)); return (int)o >= 3; }; env.Process(TestFilterCallsWorseCaseGetProcess(store, filterLogger, log)); env.Process(TestFilterCallsWorstCasePutProcess(store, log)); env.Run(); Assert.IsTrue(log.SequenceEqual(new[] { "put 0", "check 0", "put 1", "check 0", "check 1", "put 2", "check 0", "check 1", "check 2", "put 3", "check 0", "check 1", "check 2", "check 3", "get 3" })); }
public override object Execute(Environment e, object[] args) { e.Set(varname, e.Run(Pieces.ToArray())); return null; }
public override object Execute(Environment e, object[] args) { object o = null; while (IExtendFramework.Converter.ObjectToBoolean(e.Run(new object[] {WhilePiece}))) { o = e.Run(Pieces.ToArray()); } return o; }
public override object Execute(Environment e, object[] args) { object o = null; if (IExtendFramework.Converter.ObjectToBoolean(e.Run(new object[] { Decider} ))) { o = e.Run(TruePieces.ToArray()); } else { o = e.Run(ElsePieces.ToArray()); } return o; }
public override object Execute(Environment e, object[] args) { var = var.Trim(); int _v = 0; object o = null; e.Set(var, _v); for (; _v < max; _v += incremental) { e.Set(var, _v); o = e.Run(Pieces.ToArray()); } e.Set(var, null); return o; }
public void TestNegativeTimeout() { var env = new Environment(); env.Process(TestNegativeTimeout(env)); env.Run(); }