-
Notifications
You must be signed in to change notification settings - Fork 0
/
lp-and-fix.jl
26 lines (20 loc) · 742 Bytes
/
lp-and-fix.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
using JuMP
function lp_and_fix(w,D,p,W)
m = size(D,1)
n = size(D,2)
model = Model(optimizer_with_attributes(Gurobi.Optimizer))
# Decision variables
@variable(model, X[i in 1:m,j in 1:n], lower_bound = 0)
@variable(model, Y[j in 1:n], lower_bound = 0)
# Objective function
@objective(model, Min, sum(D[i,j]*X[i,j] for i in 1:m, j in 1:n))
# Constraints
@constraint(model, [i in 1:m], sum(X[i,j] for j in 1:n)==1)
@constraint(model, sum(Y[j] for j in 1:n) == p)
@constraint(model, [i in 1:m, j in 1:n], X[i,j]<=Y[j])
@constraint(model, [j in 1:n], sum(w[i]*X[i,j] for i in 1:m)<=W)
# Solving the model
status = optimize!(model)
x_val = value.(X)
return x_val
end