-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassignmentProblem.jl
More file actions
38 lines (31 loc) · 895 Bytes
/
assignmentProblem.jl
File metadata and controls
38 lines (31 loc) · 895 Bytes
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
30
31
32
33
34
35
36
37
38
using LinearAlgebra
using JuMP
using GLPK
# Matrix for cost
c = [11 12 6 16 3
9 16 19 18 12
8 10 11 7 6
6 10 13 9 9
8 10 11 10 5]
n = size(c)[1]
model = Model(GLPK.Optimizer)
# Variables x
@variable(model,x[i = 1:n, j=1:n] >= 0)
# Objective function you want to minimize
@objective(model, Min, sum(c[i,j] * x[i,j] for i in 1:n for j in 1:n))
# Constraints
@constraint(model, row_con[i = 1:n],sum(x[i,j] for j in 1:n) == 1)
@constraint(model, column_con[j = 1:n],sum(x[i,j] for i in 1:n) == 1)
optimize!(model)
#print(model) # Print the whole model
# Pretty console output
println("\n\n\nResult:\nWorker\tTask\tCost")
for i in 1:n
for j in 1:n
if value(x[i,j]) > 0
println(" ",i,"\t ",j,"\t ",c[i,j])
end
end
end
println("----------------------")
println("Total Cost: ", objective_value(model))