Hello! im new using Julia and i was trying to modeling this:
Julia > import Pkg; Pkg.add(“JuMP”)
Julia > using JuMP
Julia > m = Model()
Julia > @variable(m, x1)
Julia > @variable(m, x2)
Julia > @variable(m, x3)
Julia > @variable(m, x4)
julia> @objective(m,Max,-x1 + 7x2 + 14x3 +2x4)
julia> @constraint(m, -x1+x2+x3+x4 >=7)
julia> @constraint(m, x1+27x2+30x3<=89)
julia> @constraint(m, x3 <= 2)
when i use “optimize!(m)”, Julia send me this error "ERROR: NoOptimizer()
how can i fixed it?
another question: x1 is a free variable, how can i created a free variable?
sorry guys for my bad english, actually im taking english classes to improve it.
JuMP is just a tool for describing your optimization problem, so you also need an optimizer to solve the problem. It looks like https://github.com/JuliaOpt/GLPK.jl would work for your case. You can install it with
Pkg.add("GLPK") and then use it like this:
m = Model(with_optimizer(GLPK.Optimizer))
For more information, see: http://www.juliaopt.org/JuMP.jl/v0.19.0/quickstart/#Quick-Start-Guide-1
Can you explain what you mean?
x1 is already a variable with no bounds in the optimization problem you’ve written. Do you need something other than that?
Also, by the way, rather than making variables with numbers in their names, like
x2, etc., I would suggest making a vector of variables:
julia> @variable(m, x[1:4])
Doing this can make it easier to add constraints to many variables at once:
julia> @constraint(m, x[2:4] .>= 0)
x ≥ 0.0
x ≥ 0.0
x ≥ 0.0