help modeling a problem

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,x2-x4==1)
julia> @constraint(m, x3 <= 2)
julia> @constraint(m,x2>=0)
julia> @constraint(m,x3>=0)
julia> @constraint(m,x4>=0)
julia> optimize!(m)

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 would work for your case. You can install it with Pkg.add("GLPK") and then use it like this:

using JuMP
using GLPK
m = Model(with_optimizer(GLPK.Optimizer))
@variable(m, x1)

For more information, see:

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 x1, x2, etc., I would suggest making a vector of variables:

julia> @variable(m, x[1:4])
4-element Array{VariableRef,1}:

Doing this can make it easier to add constraints to many variables at once:

julia> @constraint(m, x[2:4] .>= 0)
3-element Array{ConstraintRef{Model,MathOptInterface.ConstraintIndex{MathOptInterface.ScalarAffineFunction{Float64},MathOptInterface.GreaterThan{Float64}},ScalarShape},1}:
 x[2] ≥ 0.0
 x[3] ≥ 0.0
 x[4] ≥ 0.0