Programming: Optimisation and Operations Research Algorithms
Programming: Optimisation and Operations Research Algorithms
with Julia
Université de Nantes
Département Informatique – UFR Sciences et Techniques
France
Install:
using Pkg
Pkg.add("JuMP")
Pkg.add("GLPK")
Setup:
using JuMP
using GLPK
Install:
using Pkg
Pkg.add("JuMP")
Pkg.add("GLPK")
Setup:
using JuMP
using GLPK
Install:
using Pkg
Pkg.add("JuMP")
Pkg.add("GLPK")
Setup:
using JuMP
using GLPK
Example:
» fi
max z px q “ x1 ` 3x2 p0q
—
— s .t x1 ` x2 ď 14 p1q ffi
ffi
—
— ´2x1 ` 3x2 ď 12 p2q ffi
ffi
– 2x1 ´ x2 ď 12 p3q fl
x1 , x2 ě 0 p4q
Creating a Model:
modName = Model(solver)
Result:
» fi
— ffi
— ffi
— ffi
– fl
Defining Variables:
Result:
» fi
— ffi
— ffi
— ffi
– fl
x1 , x2 ě 0 p4q
Defining Objective:
Result:
» fi
max z px q “ x1 ` 3x2 p0q
— ffi
— ffi
— ffi
– fl
x1 , x2 ě 0 p4q
Defining Constraints:
Result:
» fi
max z px q “ x1 ` 3x2 p0q
— s.t x1 ` x2 ď 14 p1q ffi
´2x1 ` 3x2 ď 12 p2q
— ffi
— ffi
2x1 ´ x2 ď 12 p3q
– fl
x1 , x2 ě 0 p4q
The model:
§ print a summary of the problem:
julia> @show(model)
julia> print(model)
optimize!(modName )
julia> optimize!(model)
julia> solution_summary(model)
julia> solution_summary(model)
julia> solution_summary(model)
julia> solution_summary(model)
termination_status(modName )
§ INFEASIBLE:
The algorithm concluded that no feasible solution exists.
§ TIME_LIMIT:
The algorithm stopped after a user-specified computation time.
§ NUMERICAL_ERROR:
The algorithm stopped because a numerical error.
§ etc.
termination_status(modName )
§ INFEASIBLE:
The algorithm concluded that no feasible solution exists.
§ TIME_LIMIT:
The algorithm stopped after a user-specified computation time.
§ NUMERICAL_ERROR:
The algorithm stopped because a numerical error.
§ etc.
Ó
¨ ˛
1 1
c “ p1, 3q, d “ p14, 12, 12q, T “ ˝ ´2 3 ‚
2 ´1
» ř2 fi
max z px q “ cx p0q
řj2“1 j j
– s .t j “1 tij xj ď di i “ 1, 3 p1 ´ 3q fl
xj ě 0 j “ 1, 2 p4q
Example (cont’d):
¨ ˛
1 1
c “ p1, 3q, d “ p14, 12, 12q, T “ ˝ ´2 3 ‚
2 ´1
c = [1, 3]
d = [14, 12, 12]
T = [1 1 ; -2 3; 2 -1]
n,m = size(T)
Example (cont’d):
» ř2 fi
max z px q “ cj xj p0q
— řj2“1 ffi
– s.t j “1 tij xj ď di i “ 1, 3 p1 ´ 3q fl
xj ě 0 j “ 1, 2 p4q
julia> md = Model(GLPK.Optimizer)
julia> @variable(md, x[1:m]ě0)
julia> @objective(md, Max,sum(c[j]*x[j] for j=1:m))
julia> @constraint(md, cst[i=1:n],sum(T[i,j]*x[j]
for j=1:m)ďd[i])
Structured variables:
§ Arrays (one-based integer ranges)
Structured variables:
§ Arrays (one-based integer ranges)
Deleting variables:
julia> delete(model, x)
Deleting variables:
julia> delete(model, x)
Modify an objective:
call @objective with the new objective function:
Modify an objective:
call @objective with the new objective function:
set_normalized_rhs(constraintID, value )
delete(model, constraintID )
set_normalized_rhs(constraintID, value )
delete(model, constraintID )
set_normalized_rhs(constraintID, value )
delete(model, constraintID )
julia> value(x1)
julia> value(x[3])
value.(variable )
julia> value.(x)
julia> value(x1)
julia> value(x[3])
value.(variable )
julia> value.(x)
Install:
using Pkg
Pkg.add("vOptGeneric")
Pkg.add("GLPK")
Setup:
using vOptGeneric
using GLPK
Install:
using Pkg
Pkg.add("vOptGeneric")
Pkg.add("GLPK")
Setup:
using vOptGeneric
using GLPK
with1 n“5
p1 “ p10, 3, 6, 8, 2q
p2 “ p12, 9, 11, 5, 6q
w “ p4, 5, 2, 5, 6q
c “ 17
1
exercise 10.2, page 290 of Multicriteria Optimization (2nd edt), M. Ehrgott,
Springer 2005
julia> vSolve(kp,method=:epsilon,step=0.5,verbose=false)
julia> printX_E(kp)
(notebook)