Advertisement
agudonacho

Untitled

Jan 24th, 2019
825
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Julia 2.58 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, diag0[r=1:R,m=1:M], y[r,r,m] == 0)
  37. @constraint(Handball, tworefs_con[m=1:M], sum(x[r,m] for r=1:R) == 2) # Two refs per match
  38. #@constraint(Handball, ref_one_match_a_day_con[r=1:R,d=1:D],
  39. #                      sum(x[r,m]*match_time[m,d] for m=1:M) <= 1) # A referee can only be assigned to one match a day
  40. @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
  41.  
  42. # H2.1 constraints
  43. @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
  44. @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
  45. @constraint(Handball, y_Config2[r=1:R,m=1:M,rr=1:R,r!=rr], x[r,m] >= y[r,rr,m]) # y configuration
  46. @constraint(Handball, y_Config3[r=1:R,m=1:M,rr=1:R, r!=rr], x[rr,m] >= y[r,rr,m]) # y configuration
  47.  
  48.  
  49. # H2.1 objective
  50. @objective(Handball, Max, sum(y[r,rr,m]*ref_pair[r,rr] for r=1:R,rr=1:R,m=1:M))
  51.  
  52.  
  53. #************************************************************************
  54. # solve
  55. solution = solve(Handball)
  56.  
  57. #************************************************************************
  58. # Report results
  59. println("----------------------------------------");
  60. if solution == :Optimal
  61.    println("RESULTS:")
  62.    println("The maximum pairs are = $(getobjectivevalue(Handball))")
  63.  
  64.  
  65. else
  66.   println("  No solution")
  67. end
  68. println("----------------------------------------");                                   # solve
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement