Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #************************************************************************
- # Initialize
- using JuMP
- using GLPKMathProgInterface
- using Gurobi
- #************************************************************************
- # Data declaration
- include("handball_data.jl")
- (R,A) = size(referfee_arena_distances)
- (M,D) = size(match_time)
- (T,M) = size(team_match)
- # H2 Data
- last_optimal_value = 8866.0
- #************************************************************************
- # Model
- Handball = Model(solver=GurobiSolver())
- @variable(Handball, x[1:R, 1:M], Bin) # Referee r assigned to match m
- # H2 variable
- @variable(Handball, y[1:R, 1:R, 1:M], Bin) # Referee r and referee rr are assigned together for match m
- #for r in 1:R
- # for rr in 1:R
- # for m in 1:M
- # if r==rr
- # setupperbound(y[r,rr,m], 0)
- # end
- # end
- # end
- #end
- @constraint(Handball, diag0[r=1:R,m=1:M], y[r,r,m] == 0)
- @constraint(Handball, tworefs_con[m=1:M], sum(x[r,m] for r=1:R) == 2) # Two refs per match
- #@constraint(Handball, ref_one_match_a_day_con[r=1:R,d=1:D],
- # sum(x[r,m]*match_time[m,d] for m=1:M) <= 1) # A referee can only be assigned to one match a day
- @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
- # H2.1 constraints
- @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
- @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
- @constraint(Handball, y_Config2[r=1:R,m=1:M,rr=1:R,r!=rr], x[r,m] >= y[r,rr,m]) # y configuration
- @constraint(Handball, y_Config3[r=1:R,m=1:M,rr=1:R, r!=rr], x[rr,m] >= y[r,rr,m]) # y configuration
- # H2.1 objective
- @objective(Handball, Max, sum(y[r,rr,m]*ref_pair[r,rr] for r=1:R,rr=1:R,m=1:M))
- #************************************************************************
- # solve
- solution = solve(Handball)
- #************************************************************************
- # Report results
- println("----------------------------------------");
- if solution == :Optimal
- println("RESULTS:")
- println("The maximum pairs are = $(getobjectivevalue(Handball))")
- else
- println(" No solution")
- end
- println("----------------------------------------"); # solve
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement