예제 #1
0
 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));
       }
 }
        public void TestRunResumeDApi()
        {
            /* Stopped simulation can be resumed. */
              var env = new Environment(defaultStep: TimeSpan.FromMinutes(1));
              var events = new List<Event>() {
            env.TimeoutD(5),
            env.TimeoutD(10),
            env.TimeoutD(15),
            env.TimeoutD(20)
              };

              Assert.AreEqual(env.NowD, 0);
              Assert.AreEqual(env.PeekD(), 5);
              Assert.IsFalse(events.Any(x => x.IsProcessed));

              env.RunD(10);
              Assert.AreEqual(env.NowD, 10);
              Assert.AreEqual(env.PeekD(), 10);
              Assert.IsTrue(events[0].IsProcessed);
              Assert.IsFalse(events[1].IsProcessed);
              Assert.IsFalse(events[2].IsProcessed);

              env.RunD(5);
              Assert.AreEqual(env.NowD, 15);
              Assert.AreEqual(env.PeekD(), 15);
              Assert.IsTrue(events[0].IsProcessed);
              Assert.IsTrue(events[1].IsProcessed);
              Assert.IsFalse(events[2].IsProcessed);

              env.RunD(1);
              Assert.AreEqual(env.NowD, 16);
              Assert.AreEqual(env.PeekD(), 20);
              Assert.IsTrue(events[0].IsProcessed);
              Assert.IsTrue(events[1].IsProcessed);
              Assert.IsTrue(events[2].IsProcessed);

              env.RunD();
              Assert.AreEqual(env.NowD, 20);
              Assert.AreEqual(env.PeekD(), double.MaxValue);
        }
 private static IEnumerable<Event> AProcess(Environment env, List<string> log)
 {
     while (env.NowD < 2) {
     log.Add(env.NowD.ToString("00", CultureInfo.InvariantCulture.NumberFormat));
     yield return env.TimeoutD(1);
       }
 }
예제 #4
0
 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);
 }
예제 #5
0
 private IEnumerable<Event> TestOperatorAndBlockedProcess(Environment env)
 {
     var timeout = env.TimeoutD(1);
       var @event = new Event(env);
       yield return env.TimeoutD(1);
       var condition = timeout & @event;
       Assert.IsFalse(condition.IsTriggered);
 }
예제 #6
0
 private IEnumerable<Event> TestAndConditionBlockedProcess(Environment env)
 {
     var t1 = env.TimeoutD(1);
       var e = new Event(env);
       yield return t1;
       yield return t1 & e;
       Assert.Fail("Process should not recover");
 }