Fixing old code and ran into SetObjective error

I am working through an old code, and having to change a bunch of stuff to work with the new JuMP package. (ex. replacing {} with (), replacing @DefVar with variable, replacing AddConstraint with constraint, etc.)

I’ve run into the following error when running the code:

ERROR: LoadError: LoadError: UndefVarError: @setObjective not defined

Here is the first line of the code with that wording:

Objective

@setObjective(m, Max, sum{skaters[i,:Projection]*skaters_lineup[i], i=1:num_skaters} + sum{goalies[i,:Projection]*goalies_lineup[i], i=1:num_goalies})

Any help on what to change here?

A very large number of things have changed if you are still using @defVar.

You should read the latest documentation: http://www.juliaopt.org/JuMP.jl/v0.20.0/quickstart/

Right, I’ve figured out most of the changes. I’m wondering if anyone can help with this particular one. Thanks in advance!

The page linked has @objective

I am a complete newbie with Julia or any programming tbh. I downloaded a code a couple years ago, and have been using it forever. I got a new computer, downloaded Julia, then I discovered all of the changes that took effect with the new versions. I’ve been trying to rewrite the code with all of the new formatting, but have gotten stuck on this one line (in original post). I read through the page that was linked, but it looks like it is showing different commands to give to Julia - I am looking for what the new terminology is for @setObjective so I can edit the code. Hopefully what I’m saying makes sense. I appreciate you guys trying to help, but I’m looking for a more direct answer (if there is one, of course), as I’m not really familiar with the language used on that page that was linked.

Direct answer: change @setObjective to @objective.

Better answer: that’s unlikely to be the only problem you have. For example, solve is now optimize!, getvalue is now value, and all the solvers have changed, so CbcSolver() is no longer a thing. So, you should spend the time to read through the documentation. The QuickStart guide has most of what you’ll need.

1 Like