-
Notifications
You must be signed in to change notification settings - Fork 30
/
SimpleShop.cs
42 lines (37 loc) · 1.35 KB
/
SimpleShop.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#region License Information
/*
* This file is part of SimSharp which is licensed under the MIT license.
* See the LICENSE file in the project root for more information.
*/
#endregion
using System;
using System.Collections.Generic;
using static SimSharp.Distributions;
namespace SimSharp.Samples {
class SimpleShop {
static TimeSpan delay = TimeSpan.Zero;
private static readonly BoundedTime MachineProc = POS(N(TimeSpan.FromSeconds(20), TimeSpan.FromSeconds(5)));
private static readonly BoundedTime PackerProc = POS(N(TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(2)));
static IEnumerable<Event> Machine(Simulation env, Resource packer) {
while (true) {
yield return env.Timeout(MachineProc);
var token = packer.Request();
yield return token;
delay += env.Now - token.Time;
env.Process(Pack(env, packer, token));
}
}
static IEnumerable<Event> Pack(Simulation env, Resource packer, Request token) {
yield return env.Timeout(PackerProc);
packer.Release(token);
}
public void Simulate() {
var env = new Simulation(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);
}
}
}