-
Notifications
You must be signed in to change notification settings - Fork 0
/
transport.cs
105 lines (92 loc) · 2.73 KB
/
transport.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication14
{
abstract class Event
{
public readonly uint time;
public Event(uint time)
{
this.time = time;
}
public virtual void process() { }
}
class NewPassangerEvent : Event
{
public readonly Stop where;
public NewPassangerEvent(uint time, Stop where) : base(time) {
this.where = where;
}
public override void process()
{
Console.WriteLine("{0}: New passanger at {1}", Program.time, where.name);
new Passanger(where);
}
}
class Stop
{
public List<Passanger> passangers;
public readonly uint timeToNext;
public readonly uint passangerInterval;
public readonly string name;
public Stop(string name, uint timeToNext, uint passangerInterval)
{
this.name = name;
this.timeToNext = timeToNext;
this.passangerInterval = passangerInterval;
this.passangers = new List<Passanger>();
}
}
class Passanger
{
readonly uint arrival;
readonly Stop stop;
public Passanger(Stop stop)
{
this.stop = stop;
this.stop.passangers.Add(this);
arrival = Program.time;
uint nextArrival = Program.time + 3;
Program.events.Add(new NewPassangerEvent( nextArrival, stop));
}
}
class Program
{
public static uint time;
public static List<Event> events;
public static List<Stop> stops;
static void Main(string[] args)
{
time = 0;
stops = new List<Stop>(){
new Stop("Kastrychnickaja", 200, 3),
new Stop("Niamiha", 180, 6),
new Stop("Frunzenskaja", 190, 5),
new Stop("Niamiha", 300, 6)
};
events = new List<Event>() {
new NewPassangerEvent(1,stops[0]),
new NewPassangerEvent(2,stops[1]),
new NewPassangerEvent(3,stops[2]),
new NewPassangerEvent(5,stops[3])
};
while (time < 10) {
uint mintime = events[0].time;
Event upcomingEvent = events[0];
foreach (Event ev in events)
{
if (ev.time < mintime)
{
mintime = ev.time;
upcomingEvent = ev;
}
}
time = upcomingEvent.time;
upcomingEvent.process();
}
}
}
}