brewersfan1976

request_matching.rb

May 28th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.40 KB | None | 0 0
  1. def requestMatching(pros, distances, travelPreferences)
  2.     pros_length = pros.length
  3.     matching_score = Array.new(pros_length) {Array.new}
  4.     non_matching_score = Array.new(pros_length) {Array.new}
  5.     final_array = Array.new
  6.     x = 0
  7.     y = 0
  8.     z = 0
  9.    
  10.     while (x < pros_length)
  11.         if distances[x] <= travelPreferences[x] then
  12.            matching_score[y][0] = distances[x]
  13.            matching_score[y][1] = pros[x]
  14.            y = y + 1
  15.         else
  16.            non_matching_score[z][0] = distances[x] - travelPreferences[x]
  17.            non_matching_score[z][1] = pros[x]
  18.            z = z + 1
  19.         end
  20.            
  21.         x = x + 1
  22.     end
  23.        
  24.     matching_score = matching_score.delete_if {|elem| elem.flatten.empty?}
  25.     matching_score = matching_score.sort
  26.     non_matching_score = non_matching_score.delete_if {|elem| elem.flatten.empty?}
  27.     non_matching_score = non_matching_score.sort
  28.        
  29.     x = 0
  30.     y = 0
  31.     array_length = matching_score.length
  32.        
  33.     while (y < array_length)
  34.           final_array[x] = matching_score[y][1]
  35.           x = x + 1
  36.           y = y + 1
  37.     end
  38.        
  39.     array_length = 5 - final_array.length
  40.     y = 0
  41.    
  42.     while (y < array_length and y <= non_matching_score.length - 1)
  43.           final_array[x] = non_matching_score[y][1]
  44.           x = x + 1
  45.           y = y + 1
  46.     end
  47.    
  48.     return final_array
  49. end
Advertisement
Add Comment
Please, Sign In to add comment