Skip to content

Commit

Permalink
Merge pull request #70 from tamu-edu-students/unify_algo
Browse files Browse the repository at this point in the history
Unify algo
  • Loading branch information
BenFan1002 authored Nov 22, 2024
2 parents 4857cf7 + b61be5e commit f945983
Show file tree
Hide file tree
Showing 14 changed files with 450 additions and 500 deletions.
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ gem 'omniauth-google-oauth2'
gem 'omniauth-rails_csrf_protection'

# For the professor/class matching
gem 'hungarian_algorithm'
gem 'rulp', require: false
# CSV parsing
gem 'csv'
Expand Down
2 changes: 0 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ GEM
globalid (1.2.1)
activesupport (>= 6.1)
hashie (5.0.0)
hungarian_algorithm (1.0.0)
i18n (1.14.6)
concurrent-ruby (~> 1.0)
importmap-rails (2.0.1)
Expand Down Expand Up @@ -456,7 +455,6 @@ DEPENDENCIES
debug
factory_bot_rails
faker
hungarian_algorithm
importmap-rails
jbuilder
matrix
Expand Down
16 changes: 10 additions & 6 deletions app/controllers/room_bookings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def generate_schedule
'capacity' => room.capacity
}
end
times = TimeSlot.pluck(:day, :start_time, :end_time, :id)
times = TimeSlot.where(slot_type: 'LEC').pluck(:day, :start_time, :end_time, :id)
instructors = Instructor.where(schedule_id: params['schedule_id']).pluck(:id, :before_9, :after_3, :max_course_load).map do |i, b, a, c|
{ 'id' => i, 'before_9' => b,
'after_3' => a, 'max_course_load' => c }
Expand All @@ -167,11 +167,15 @@ def generate_schedule

# Offload solve to service
begin
total_unhappiness = ScheduleSolver.solve(classes, active_rooms, times, instructors, locks)
max_unhappiness = classes.length * 10 # Individual unhappiness is capped at 10
satisfaction_rate = (100 * (max_unhappiness - total_unhappiness).to_f / max_unhappiness).to_i
redirect_to schedule_room_bookings_path(@schedule, active_tab: params[:active_tab]),
notice: "Schedule generated with #{satisfaction_rate}% satisfaction"
total_happiness, relaxed = ScheduleSolver.solve(classes, active_rooms, times, instructors, locks)
max_happiness = classes.length * 10 # Individual happiness is capped at 10
satisfaction_rate = (100 * total_happiness.to_f / max_happiness).to_i
msg = if relaxed
"Schedule generated under relaxed time constraints with #{satisfaction_rate}% satisfaction"
else
"Schedule generated with #{satisfaction_rate}% satisfaction"
end
redirect_to schedule_room_bookings_path(@schedule, active_tab: params[:active_tab]), notice: msg
rescue StandardError => e
redirect_to schedule_room_bookings_path(@schedule, active_tab: params[:active_tab]), alert: e.message
end
Expand Down
Loading

0 comments on commit f945983

Please sign in to comment.