forked from muratakcs/Optimization
-
Notifications
You must be signed in to change notification settings - Fork 0
/
swimrelay.jl
29 lines (18 loc) · 852 Bytes
/
swimrelay.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
using JuMP, Clp, NamedArrays
strokes = [ :backstroke, :breaststroke, :butterfly, :freestyle ]
names = [ :Carl, :Chris, :David, :Tony, :Ken ]
raw = [ 37.7 32.9 33.8 37.0 35.4
43.4 33.1 42.2 34.7 41.8
33.3 28.5 38.9 30.4 33.6
29.2 26.4 29.6 28.5 31.1 ]
times = NamedArray( raw, (strokes,names), ("stroke","name"))
m = Model(with_optimizer(Clp.Optimizer))
@variable(m, x[strokes,names] >= 0)
# each swimmer swims at most one event
@constraint(m, a[j in names], sum(x[i,j] for i in strokes) <= 1 )
# each event has exactly one swimmer
@constraint(m, b[i in strokes], sum(x[i,j] for j in names) == 1 )
@objective(m, Min, sum( x[i,j]*times[i,j] for i in strokes, j in names ) )
optimize!(m)
assignment = NamedArray( [ (value(x[i,j])) for i in strokes, j in names ], (strokes, names), ("stroke","name"))
println(assignment)