This repository has been archived by the owner on Apr 9, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
queue_disciplines.rb
64 lines (50 loc) · 1.61 KB
/
queue_disciplines.rb
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
# This queue discipline tries to maximize feedback among projects by minimizing takt time
class FeedbackerDiscipline
def initialize projects
@projects = projects.clone
@index = 0
end
def next
projects = (@projects.select {|project| project.backlog.count > 0}).sort do |a,b|
ar = a.finished.count > 0 ? a.finished.last.lead_time : 9999
br = b.finished.count > 0 ? b.finished.last.lead_time : 9999
br <=> ar
end
#str = ""
#projects.each {|x| str += "#{x.id}:" + (x.finished.count > 0 ? x.finished.last.leadtime : 9999).to_s + ", " }
#puts str
return nil if projects.count == 0
return projects.first
end
end
# This queue discipline tries to equalize projects by backlog size
class MarxDiscipline
def initialize projects
@projects = projects.clone
@index = 0
end
def next
projects = @projects.sort {|a,b| a.backlog.count <=> b.backlog.count}
return nil if projects.last.backlog.count == 0
# puts "#{projects.last.id}"
return projects.last
end
end
# This queue discipline simply randomly selects a project...
class VegasDiscipline
def initialize projects
@projects = projects.clone
end
def next
(@projects.select {|project| project.backlog.count > 0}).sample
end
end
# First in, first out
class FifoDiscipline
def initialize projects
@projects = projects.clone
end
def next
(@projects.select {|project| project.backlog.count > 0}).first
end
end