Class: Schedsolver2::School
- Inherits:
-
Object
- Object
- Schedsolver2::School
show all
- Includes:
- Schedsolver2
- Defined in:
- lib/schedsolver2/school.rb
Constant Summary
LIBPATH, PATH, VERSION
Instance Attribute Summary collapse
Instance Method Summary
collapse
libpath, #log, log, #log=, log=, path, require_all_libs_relative_to
Constructor Details
#initialize(si, ts, cs) ⇒ School
Returns a new instance of School.
8
9
10
11
12
13
14
|
# File 'lib/schedsolver2/school.rb', line 8
def initialize si, ts, cs
@si, @ts, @cs = si, ts, cs
@consts = generate_constants
@scheds = []
verify_initialize_args
parse_part_time_constraints
end
|
Instance Attribute Details
#consts ⇒ Object
Returns the value of attribute consts.
6
7
8
|
# File 'lib/schedsolver2/school.rb', line 6
def consts
@consts
end
|
#cs ⇒ Object
Returns the value of attribute cs.
5
6
7
|
# File 'lib/schedsolver2/school.rb', line 5
def cs
@cs
end
|
#scheds ⇒ Object
Returns the value of attribute scheds.
6
7
8
|
# File 'lib/schedsolver2/school.rb', line 6
def scheds
@scheds
end
|
#si ⇒ Object
Returns the value of attribute si.
6
7
8
|
# File 'lib/schedsolver2/school.rb', line 6
def si
@si
end
|
#ts ⇒ Object
Returns the value of attribute ts.
6
7
8
|
# File 'lib/schedsolver2/school.rb', line 6
def ts
@ts
end
|
Instance Method Details
#add(type, *args) ⇒ Object
94
95
96
97
98
99
100
101
102
|
# File 'lib/schedsolver2/school.rb', line 94
def add type, *args
case type
when :schedules
raise ArgumentError unless (args.size == 1 and args[0] > 0)
args[0].times { @scheds << Schedule.new(@consts) }
when :hard_constraint
@cs[:h] << args[0]
end
end
|
#days ⇒ Object
78
79
80
|
# File 'lib/schedsolver2/school.rb', line 78
def days
@consts[:days]
end
|
#db ⇒ Object
171
172
173
174
|
# File 'lib/schedsolver2/school.rb', line 171
def db
@scheds[0][:mon, 8, :Art] = 'TEST'
@scheds[1][:wed, 12, :Music] = 'TEST'
end
|
#et_ids ⇒ Object
86
87
88
|
# File 'lib/schedsolver2/school.rb', line 86
def et_ids
@consts[:et_ids]
end
|
#generate_constants ⇒ Object
60
61
62
63
64
65
66
67
|
# File 'lib/schedsolver2/school.rb', line 60
def generate_constants
h = Hash.new
h[:days] = [:mon, :tue, :wed, :thu, :fri]
h[:times] = generate_times
h[:et_ids] = @ts[:e].map {|t| t.id}
h[:ht_ids] = @ts[:h].map {|t| t.id}
return h
end
|
#generate_schedule(index) ⇒ Object
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
# File 'lib/schedsolver2/school.rb', line 104
def generate_schedule(index)
i = index
@ts[:h].shuffle.each do |ht|
ht_id = ht.id
count = nil
count = ClassCounter.new(@consts[:et_ids])
@ts[:e].shuffle.each do |et|
et_id = et.id
w_remaining = @cs[:ecs_per_week] - count.by_et_id(et_id)
if w_remaining == 0
break
end
@consts[:times].shuffle.each do |time|
w_remaining = @cs[:ecs_per_week] - count.by_et_id(et_id)
if w_remaining == 0
break
end
@consts[:days].shuffle.each do |day|
d_remaining = @cs[:max_ecs_per_day] - count.by_day(day)
w_remaining = @cs[:ecs_per_week] - count.by_et_id(et_id)
if d_remaining == 0
next
elsif w_remaining == 0
break
elsif @scheds[i][day, time, et_id] != nil
next
elsif count[day, et_id] > 0
next
elsif not et.working?(day)
next
end
begin
@scheds[i][day, time, et_id] = ht_id
rescue InsanityError
next
else
count[day, et_id] += 1
d_remaining = @cs[:max_ecs_per_day] - count.by_day(day)
w_remaining = @cs[:ecs_per_week] - count.by_et_id(et_id)
end
end
end
end
end
end
|
#generate_times ⇒ Object
69
70
71
72
73
74
75
76
|
# File 'lib/schedsolver2/school.rb', line 69
def generate_times
ts, t = [], @si[:start_time]
@si[:num_blocks].times do
ts << t
t += @si[:block_size]
end
return ts
end
|
#ht_ids ⇒ Object
90
91
92
|
# File 'lib/schedsolver2/school.rb', line 90
def ht_ids
@consts[:ht_ids]
end
|
#parse_part_time_constraints ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/schedsolver2/school.rb', line 31
def parse_part_time_constraints
@cs[:part_time] ||= {}
@ts[:e].each do |et|
not_work_days = (days - et.work_days)
if not_work_days == [] then next end
s_d = Constraint.days_descriptor(not_work_days, times, [et.id])
new_pt_c = Constraint.new(:type => :part_time,
:et_ids => [et.id],
:s_ds => [s_d],
:name => "et#{et.id} part time")
@cs[:part_time][et.id] = new_pt_c
end
end
|
#print(attr) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/schedsolver2/school.rb', line 16
def print attr
case attr
when :schedules
@scheds.each {|s| log.info("\n" + s.to_s) }
when :school_info
log.info("SCHOOL INFO #{@si}")
when :consts
log.info("CONSTS #{@consts}")
when :teachers
log.info("TEACHERS #{@ts}")
when :constraints
log.info("CONSTRAINTS #{@cs}")
end
end
|
#times ⇒ Object
82
83
84
|
# File 'lib/schedsolver2/school.rb', line 82
def times
@consts[:times]
end
|
#verify_initialize_args ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/schedsolver2/school.rb', line 46
def verify_initialize_args
check = ((@si[:end_time] - @si[:start_time]) == (@si[:num_blocks] * @si[:block_size]))
raise ArgumentError, "si: end-start != num*size" unless check == true
@ts[:e].each do |t|
raise ArgumentError, "ts:e: has non-teacher" unless t.class == Teacher
end
@ts[:h].each do |t|
raise ArgumentError, "ts:h: has non-teacher" unless t.class == Teacher
end
end
|