In [1]:

using MathProgBase




In [2]:




In [8]:

methods(linprog)




Out[8]:

4 methods for generic function linprog: linprog(c::Union{Array{T<:Union{Char,Real},1},Char,Real}, A::AbstractArray{T<:Any,2}, rowlb::Union{Array{T<:Union{Char,Real},1},Char,Real}, rowub::Union{Array{T<:Union{Char,Real},1},Char,Real}, lb::Union{Array{T<:Union{Char,Real},1},Char,Real}, ub::Union{Array{T<:Union{Char,Real},1},Char,Real}) at /opt/julia_packages/.julia/v0.5/MathProgBase/src/HighLevelInterface/linprog.jl:95  linprog(c::Union{Array{T<:Union{Char,Real},1},Char,Real}, A::AbstractArray{T<:Any,2}, rowlb::Union{Array{T<:Union{Char,Real},1},Char,Real}, rowub::Union{Array{T<:Union{Char,Real},1},Char,Real}, lb::Union{Array{T<:Union{Char,Real},1},Char,Real}, ub::Union{Array{T<:Union{Char,Real},1},Char,Real}, solver::MathProgBase.SolverInterface.AbstractMathProgSolver) at /opt/julia_packages/.julia/v0.5/MathProgBase/src/HighLevelInterface/linprog.jl:95  linprog(c, A, rowlb, rowub) at /opt/julia_packages/.julia/v0.5/MathProgBase/src/HighLevelInterface/linprog.jl:99  linprog(c, A, rowlb, rowub, solver::MathProgBase.SolverInterface.AbstractMathProgSolver) at /opt/julia_packages/.julia/v0.5/MathProgBase/src/HighLevelInterface/linprog.jl:99


\begin{split}\min_{x,y}\quad &-x\\ s.t. \quad &2x + y \leq 1.5\\ & x \geq 0, y \geq 0\end{split}

### Form 1

linprog(c, A, lb, ub, l, u)

\begin{split}\min_{x}\quad &c^Tx\\ s.t.\quad &lb \leq Ax \leq ub\\ &l \leq x \leq u\\\end{split}


In [3]:

sol = linprog([-1,0],[2 1],-Inf,1.5,0,Inf)




Out[3]:

MathProgBase.HighLevelInterface.LinprogSolution(:Optimal,-0.75,[0.75,0.0],Dict{Any,Any}(Pair{Any,Any}(:redcost,[0.0,0.5]),Pair{Any,Any}(:lambda,[-0.5])))



#### Form 1'

(shortcut with implicit [0,Inf] constraints)



In [6]:

sol = linprog([-1,0],[2 1],-Inf,1.5)




Out[6]:

MathProgBase.HighLevelInterface.LinprogSolution(:Optimal,-0.75,[0.75,0.0],Dict{Any,Any}(Pair{Any,Any}(:redcost,[0.0,0.5]),Pair{Any,Any}(:lambda,[-0.5])))



### Form 2

linprog(c, A, sense, b, l, u)

\begin{split}\min_{x}\quad &c^Tx\\ s.t. \quad &a_i^Tx \text{ sense}_i \, b_i \forall\,\, i\\ &l \leq x \leq u\\\end{split}


In [13]:

sol = linprog([-1,0],[2 1],'<',1.5)




Out[13]:

MathProgBase.HighLevelInterface.LinprogSolution(:Optimal,-0.75,[0.75,0.0],Dict{Any,Any}(Pair{Any,Any}(:redcost,[0.0,0.5]),Pair{Any,Any}(:lambda,[-0.5])))




In [10]:

sol = linprog([-1,0],[2 1; 1 0],['<','>'],[1.5; 0.25])




Out[10]:

MathProgBase.HighLevelInterface.LinprogSolution(:Optimal,-0.75,[0.75,0.0],Dict{Any,Any}(Pair{Any,Any}(:redcost,[0.0,0.5]),Pair{Any,Any}(:lambda,[-0.5,0.0])))