Advertisement
agudonacho

Untitled

Jan 23rd, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. #************************************************************************
  2. # Initialize
  3. using JuMP
  4. using GLPKMathProgInterface
  5. using Gurobi
  6.  
  7. #************************************************************************
  8. # Data declaration
  9.  
  10. include("handball_data.jl")
  11. (R,A) = size(referfee_arena_distances)
  12. (M,D) = size(match_time)
  13. (T,M) = size(team_match)
  14.  
  15. # H2 Data
  16. last_optimal_value = 8866.0
  17.  
  18. #************************************************************************
  19. # Model
  20.  
  21. Handball = Model(solver=GurobiSolver())
  22.  
  23. @variable(Handball, x[1:R, 1:M], Bin) # Referee r assigned to match m
  24.  
  25. # H2 variable
  26. @variable(Handball, y[1:R, 1:R, 1:M], Bin) # Referee r and referee rr are assigned together for match m
  27. for r in 1:R
  28. for rr in 1:R
  29. for m in 1:M
  30. if r==rr
  31. setupperbound(y[r,rr,m], 0)
  32. end
  33. end
  34. end
  35. end
  36. @constraint(Handball, tworefs_con[m=1:M], sum(x[r,m] for r=1:R) == 2) # Two refs per match
  37. @constraint(Handball, ref_one_match_a_day_con[r=1:R,d=1:D],
  38. sum(x[r,m]*match_time[m,d] for m=1:M) <= 1) # A referee can only be assigned to one match a day
  39. @constraint(Handball, availability_con[r=1:R, d=1:D], sum(x[r,m]*match_time[m,d] for m=1:M) <= 1 - ref_not_available[r,d]) # Referee r must be available for be assigned to day d
  40.  
  41. # H2.1 constraints
  42. @constraint(Handball, sum(x[r,m]*referfee_arena_distances[r,a]*match_areana[m,a] for a=1:A, m=1:M, r=1:R) <= last_optimal_value) # The distance must be the same as the last calculated optimal value
  43. @constraint(Handball, y_Config1[r=1:R, rr=1:R, m=1:M, r!=rr], x[r,m] + x[rr,m] - 1 <= y[r,rr,m]) # y configuration: if referee r and rr are together in match m, then y = 1
  44. @constraint(Handball, y_Config2[r=1:R,m=1:M,rr=1:R,r!=rr], x[r,m] >= y[r,rr,m]) # y configuration
  45. @constraint(Handball, y_Config2[r=1:R,m=1:M,rr=1:R, r!=rr], x[rr,m] >= y[r,rr,m]) # y configuration
  46.  
  47.  
  48. # H2.1 objective
  49. @objective(Handball, Max, sum(y[r,rr,m]*ref_pair[r,rr] for r=1:R,rr=1:R,m=1:M))
  50.  
  51.  
  52. #************************************************************************
  53. # solve
  54. solution = solve(Handball)
  55.  
  56. #************************************************************************
  57. # Report results
  58. println("----------------------------------------");
  59. if solution == :Optimal
  60. println("RESULTS:")
  61. println("The minimum distance is = $(getobjectivevalue(Handball))")
  62.  
  63.  
  64. else
  65. println(" No solution")
  66. end
  67. println("----------------------------------------"); # solve
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement