2

Very new to Julia and trying to work through some code. I keep getting this error: "ERROR: LoadError: LoadError: UndefVarError: @defVar not defined". The start of the code is below where I define the @defVar. Julia Version 1.1.1 (2019-05-16). Here is the code I am using:

using DataFrames
using GLPKMathProgInterface
using JuMP

num_lineups = 6
num_overlap = 4

path_data = "/users/matt/desktop/example_players.csv"
path_data2 = "/users/matt/desktop/example_players2.csv"
path_to_output= "/users/matt/desktop/output.csv"

m = Model(solver=GLPKSolverMIP())
    @defVar(m, players_a_lineup[i=1:num_players_a], Bin)
    @defVar(m, players_b_lineup[i=1:num_players_b], Bin)
  • 2
    Welcome to SO and Julia! The tutorial/doc/code you are using is probably very old. I think `@defVar` no longer exists in newer versions of JuMP. You can use `@variable` and try a recent tutorial/doc instead such as [JuMP examples](https://github.com/JuliaOpt/JuMP.jl/tree/master/examples) or [JuliaOpt notebooks](https://github.com/JuliaOpt/juliaopt-notebooks/). – hckr Jun 05 '19 at 16:57
  • Those resources were a tremendous help... thank you! – RedbirdFan23 Jun 05 '19 at 20:03
  • @hckr Make that an answer and let RebirdFan23 close the question? – Marcus Ritt Jun 06 '19 at 00:22
  • @MarcusRitt ... new to stack, can I close it? – RedbirdFan23 Jun 06 '19 at 16:55
  • You have to [accept an answer](https://stackoverflow.com/help/accepted-answer). I have just added one, but you could wait a bit for @hckr to add his, and accept it, otherwise accept mine. Then the question will be "officially" answered. – Marcus Ritt Jun 06 '19 at 22:07
  • Please go ahead with @MarcusRitt 's answer. If an answer is a solution to your problem, click to the checkmark next to the answer. Accepting an answer is not mandatory but it would be considered extremely good to accept the solution. – hckr Jun 07 '19 at 06:04

1 Answers1

2

You are using an old syntax (@defvar has been used up to version 0.12). For the latest Julia/JuMP version 19, your code could should read

using DataFrames
using GLPK
using JuMP
...
m = Model(with_optimizer(GLPK.Optimizer))
@variable(m, players_a_lineup[i=1:num_players_a], Bin)
@variable(m, players_b_lineup[i=1:num_players_b], Bin)
Marcus Ritt
  • 477
  • 5
  • 12