Ejemplo n.º 1
0
 public void TestTriggeredTimeout()
 {
     var env = new Environment();
       env.Process(TestTriggeredTimeout(env));
       env.Run();
       Assert.AreEqual(2, env.NowD);
 }
Ejemplo n.º 2
0
 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);
 }
Ejemplo n.º 3
0
 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();
 }
Ejemplo n.º 4
0
 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);
 }
Ejemplo n.º 5
0
 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);
 }
Ejemplo n.º 6
0
 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));
 }
Ejemplo n.º 7
0
 /// <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;
 }
Ejemplo n.º 8
0
 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" }));
 }
Ejemplo n.º 10
0
 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);
 }
Ejemplo n.º 11
0
 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
 }
Ejemplo n.º 12
0
 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" }));
 }
Ejemplo n.º 13
0
 /// <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;
 }
Ejemplo n.º 14
0
 /// <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;
 }
Ejemplo n.º 15
0
        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);
 }
Ejemplo n.º 17
0
 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);
        }
Ejemplo n.º 20
0
 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);
 }
Ejemplo n.º 21
0
        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);
        }
Ejemplo n.º 22
0
 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);
        }
Ejemplo n.º 24
0
        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);
        }
Ejemplo n.º 25
0
 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"
       }));
 }
Ejemplo n.º 26
0
 public override object Execute(Environment e, object[] args)
 {
     e.Set(varname, e.Run(Pieces.ToArray()));
     return null;
 }
Ejemplo n.º 27
0
 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;
 }
Ejemplo n.º 28
0
 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;
 }
Ejemplo n.º 29
0
 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;
 }
Ejemplo n.º 30
0
 public void TestNegativeTimeout()
 {
     var env = new Environment();
       env.Process(TestNegativeTimeout(env));
       env.Run();
 }