forked from myrlund/salabim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shovel-truck_minimal ruud extra.py
124 lines (113 loc) · 5.01 KB
/
shovel-truck_minimal ruud extra.py
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# -*- coding: utf-8 -*-
# A Shovel-Truck Simulator Minimal (Deterministic) - for checking failures-repairs times of trucks
# Python Ver. 2.7.13
# salabim Ver. 2.2.9
__author__ = 'panagiotou'
#
import salabim as sim
#
# INPUT DATA SECTION
# General
RND_NUM_STREAM = 12345 # random number stream
WARMUP_TIME = 120 # warm-up time in min
SIMULATION_TIME = 8 # simulation time, in hours
# Facilities (Resources)
SHOVELS_NUMBER = 1 # number of shovels
CRUSHERS_NUMBER = 1 # number of crushers
# Trucks
TRUCKS_NUMBER = 1 # number of trucks
TRUCKS_INTERARRIVAL_TIME = 2 # interarrival time for n trucks at the loading station (initially)
# Trucks Times
TRUCK_LOADING_TIME = 3 # time for truck to be loaded by the shovel (includes spotting time), in min
TRUCK_TRAVEL_TO_CRUSHER_TIME = 8 # time for truck to travel to crushers, in min
TRUCK_UNLOAD_INTO_CRUSHER_TIME = 1 # time for truck to unload into crushers, in min
TRUCK_RETURN_FROM_CRUSHER_TO_SHOVEL_TIME = 15 # time for truck to return from crushers to the loading station, in min
# Failure & Repair Times
TRUCK_MTTF = 60 # time to occur a failure of a truck (MTTF), in min
TRUCK_MTTR = 20 # time to repair a truck (MTTR), in min
class Truck(sim.Component):
"""
Circulates trucks from shovels to crushers or dump sites
"""
def setup(self):
self.truckfailure = TruckFailure(name='failure for '+self.name(),truck=self)
def process(self):
while True:
self.enter(queue_loading) # truck enters the 'Queue_for_Loading'
yield self.request(shovels) # truck requests if one shovel is available to load this truck
self.leave(queue_loading) # truck leaves the 'Queue_for_Loading'
yield self.hold(truck_loading_time) # time the shovel needs to load one truck
self.release() # truck releases the shovel
yield self.hold(truck_travel_to_crusher_time) # time for truck to travel to crushers
self.enter(queue_crusher) # truck enters the 'Queue_for_Crusher'
yield self.request(crushers) # truck requests if one dump is available to unload this truck
self.leave(queue_crusher) # truck leaves the 'Queue_for_Crusher'
yield self.hold(truck_unload_into_crusher_time) # time the truck needs to unload
self.release() # truck releases the crushers
yield self.hold(truck_return_from_crusher_to_shovel_time) # time the truck needs to return to shovels
class TruckGenerator(sim.Component):
"""
Generates n trucks, the 1st truck arrives at the loading station at time=0, the rest trucks arrive in
time intervals = trucks_interarrival_time
After all n trucks have been arrived, TruckGenerator "ends" and the n trucks circulate within the system.
"""
def process(self):
for i in range(trucks_number):
Truck()
yield self.hold(trucks_interarrival_time)
class TruckFailure(sim.Component):
"""
Generates failures for trucks
"""
def setup(self, truck):
self.truck = truck
def process(self):
while True:
yield self.hold(truck_mttf) # time to occur a failure of a truck
self.truck.passivate()
yield self.hold(truck_mttr) # time to repair this truck
self.truck.hold(self.truck.remaining_duration())
def main():
env.trace(True)
env.run(warmup_time)
shovels.reset_monitors()
crushers.reset_monitors()
queue_loading.reset_monitors()
queue_crusher.reset_monitors()
env.trace(False)
#env.run(till=(simulation_time * 60)) # sim time in hours * 60 = minutes
env.run(till=(simulation_time * 60) + warmup_time ) # sim time in hours * 60 = minutes
# print-outs
shovels.print_statistics()
crushers.print_statistics()
queue_loading.print_statistics()
queue_crusher.print_statistics()
# HOUSEKEEPING STATEMENTS
env = sim.Environment()
TruckGenerator(name='truckgenerator')
# Assignment of input data to variables
# General
sim.random_seed(RND_NUM_STREAM)
warmup_time = WARMUP_TIME
simulation_time = SIMULATION_TIME
# Facilities (Resources)
shovels_number = SHOVELS_NUMBER
crushers_number = CRUSHERS_NUMBER
# Trucks
trucks_number = TRUCKS_NUMBER
trucks_interarrival_time = TRUCKS_INTERARRIVAL_TIME
# Trucks Times
truck_loading_time = TRUCK_LOADING_TIME
truck_travel_to_crusher_time = TRUCK_TRAVEL_TO_CRUSHER_TIME
truck_unload_into_crusher_time = TRUCK_UNLOAD_INTO_CRUSHER_TIME
truck_return_from_crusher_to_shovel_time = TRUCK_RETURN_FROM_CRUSHER_TO_SHOVEL_TIME
# Failure & Repair Times
truck_mttf = TRUCK_MTTF
truck_mttr = TRUCK_MTTR
# Declarations
shovels = sim.Resource(name="SHOVEL", capacity=shovels_number)
crushers = sim.Resource(name='CRUSHER', capacity=crushers_number)
queue_loading = sim.Queue('Queue_for_Loading')
queue_crusher = sim.Queue('Queue_for_Crusher')
if __name__ == '__main__':
main()