# Julia novice. Integer programming code optimization error

**URL:** <https://discourse.julialang.org/t/julia-novice-integer-programming-code-optimization-error/6926>\
**Category:** Optimization (Mathematical)\
**Tags:** question, jump\
**Created:** [November 7, 2017, 2:10am UTC](https://discourse.julialang.org/t/julia-novice-integer-programming-code-optimization-error/6926 "2017-11-07T02:10:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![yold6](https://avatars.discourse-cdn.com/v4/letter/y/d6d6ee/32.png) [@yold6](https://discourse.julialang.org/u/yold6)\
**Post date:** [November 7, 2017, 2:10am UTC](https://discourse.julialang.org/t/julia-novice-integer-programming-code-optimization-error/6926/1 "2017-11-07T02:10:46Z")

</div>

Hello and thanks for reading this. I am new to Julia and am attempting to use JuMP to generate entries for Fanduel football tournament contests with a top heavy payoff structure. The code are my modifications to code originally presented in the paper [Picking Winners Using Integer Programming](https://arxiv.org/pdf/1604.01455v2.pdf) by David Hunter, Juan Pablo Vielma, and Tauhid Zaman. My apologies if this not the right place to ask such a question (if so, I would appreciate direction to a more suitable place). I believe I am encountering an easily-fixable error, but so far I am unable to do so. I am using Julia 0.6.0. My code is:

```julia

```

I am not allowed to upload .csv files but to run the code one needs to supply an offense.csv and a defense.csv file that contain the variables and constraints needed to solve the optimization problem. If necessary, I can provide examples and I am uploading a .jpg example of the offense.csv

 ![offense_example](https://global.discourse-cdn.com/julialang/original/3X/2/a/2a2a550073fccae139e9ed231a7c1ea709d84ef8.jpeg). The defense.csv file is similar, but lacks a “Position” column (because they are all defenses).

Finally, when I attempt to run the code, I get the error:

```julia
ERROR: LoadError: UndefVarError: i not defined
Stacktrace:
 [1] macro expansion at C:\Users\cbost\.julia\v0.6\JuMP\src\macros.jl:422 [inlined]
 [2] one_lineup_Type_3(::DataFrames.DataFrame, ::DataFrames.DataFrame, ::Array{Int64,2}, ::Int64, ::Int64, ::Int64, ::Array{Any,1}, ::Array{Any,1}, ::Array{Any,1}, ::Array{Any,1}, ::Array{Any,1}, ::Int64, ::Array{Int64,2}, ::Array{Int64,2}) at C:\Users\cbost\Desktop\FanDuel\fanduel.jl:53
 [3] create_lineups(::Int64, ::Int64, ::String, ::String, ::#one_lineup_Type_3, ::String) at C:\Users\cbost\Desktop\FanDuel\fanduel.jl:254
 [4] include_from_node1(::String) at .\loading.jl:569
 [5] include(::String) at .\sysimg.jl:14
while loading C:\Users\cbost\Desktop\FanDuel\fanduel.jl, in expression starting on line 330

```

It appears there is an index (i) error somewhere in the code, but because the stacktrace just tells me the error is in the final function call, I don’t know how to track it down. I would greatly appreciate any help or suggestions to go about solving this seemingly simple error. Thank you very much for reading this topic!

---

<div class="post-metadata">

**Author:** ![leethargo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leethargo/32/6004_2.png) [@leethargo](https://discourse.julialang.org/u/leethargo)\
**Post date:** [November 7, 2017, 8:07am UTC](https://discourse.julialang.org/t/julia-novice-integer-programming-code-optimization-error/6926/2 "2017-11-07T08:07:12Z")

</div>

Could you please highlight which line is 53 in your snippet?

I’m guessing that it might be this:

```julia
@constraint(m, sum(defense_lineup[i], i=1:num_defense) == 1)

```

I think this syntax was deprecated in favor of this:

```julia
@constraint(m, sum(defense_lineup[i] for i=1:num_defense) == 1)

```

---

<div class="post-metadata">

**Author:** ![yold6](https://avatars.discourse-cdn.com/v4/letter/y/d6d6ee/32.png) [@yold6](https://discourse.julialang.org/u/yold6)\
**Post date:** [November 7, 2017, 5:08pm UTC](https://discourse.julialang.org/t/julia-novice-integer-programming-code-optimization-error/6926/3 "2017-11-07T17:08:53Z")

</div>

Thanks very much for the reply. You are correct that is line 53. I edited the code to use “emphasis” on line 53 because I couldn’t find a “highlight” option.

```julia
_@constraint(m, sum(defense_lineup[i], i=1:num_defense) == 1)_

```

You are also correct about the syntax being deprecated. A somewhat interesting side note is that when I initially reformatted the original code and tried to run it, Julia returned warnings about that syntax being deprecated, but when I more recently tried to run the code, the warnings no longer appeared and I clearly didn’t fix them.

Anyway, I applied the correct syntax to lines 53, 56, 60, 63, 66, 69, 72, 76, 80, 81, 85, 88, and 91 (the constraints and objective) and it appears to have solved the i not defined error. I get a new error 🙂

```julia
ERROR: LoadError: MethodError: no method matching *(::Type{Array{Int64,0}}, ::JuMP.Variable)
Closest candidates are:
  *(::Any, ::Any, ::Any, ::Any...) at operators.jl:424
  *(::JuMP.Variable, ::JuMP.Variable) at C:\Users\cbost\.julia\v0.6\JuMP\src\operators.jl:56
  *(::JuMP.GenericAffExpr{Float64,JuMP.Variable}, ::JuMP.Variable) at C:\Users\cbost\.julia\v0.6\JuMP\src\operators.jl:133
  ...
Stacktrace:
 [1] addtoexpr_reorder(::JuMP.GenericAffExpr{Float64,JuMP.Variable}, ::Type{Array{Int64,0}}, ::JuMP.Variable) at C:\Users\cbost\.julia\v0.6\JuMP\src\parseExpr_staged.jl:280
 [2] macro expansion at C:\Users\cbost\.julia\v0.6\JuMP\src\parseExpr_staged.jl:489 [inlined]
 [3] macro expansion at C:\Users\cbost\.julia\v0.6\JuMP\src\macros.jl:422 [inlined]
 [4] one_lineup_Type_3(::DataFrames.DataFrame, ::DataFrames.DataFrame, ::Array{Int64,2}, ::Int64, ::Int64, ::Int64, ::Array{Any,1}, ::Array{Any,1}, ::Array{Any,1}, ::Array{Any,1}, ::Array{Any,1}, ::Int64, ::Array{Int64,2}, ::Array{Int64,2}) at C:\Users\cbost\Desktop\FanDuel\fanduel.jl:60
 [5] create_lineups(::Int64, ::Int64, ::String, ::String, ::#one_lineup_Type_3, ::String) at C:\Users\cbost\Desktop\FanDuel\fanduel.jl:254
 [6] include_from_node1(::String) at .\loading.jl:569
 [7] include(::String) at .\sysimg.jl:14
while loading C:\Users\cbost\Desktop\FanDuel\fanduel.jl, in expression starting on line 330

```

Does anyone have any suggestions for this one? Thank you!

---

<div class="post-metadata">

**Author:** ![yold6](https://avatars.discourse-cdn.com/v4/letter/y/d6d6ee/32.png) [@yold6](https://discourse.julialang.org/u/yold6)\
**Post date:** [November 7, 2017, 8:44pm UTC](https://discourse.julialang.org/t/julia-novice-integer-programming-code-optimization-error/6926/4 "2017-11-07T20:44:38Z")

</div>

It turns out I was incorrectly calling the Array function (again because the old code used a deprecated construct that I didn’t understand). Reading the documentation saves the day again! 🤣. Special thanks to leethargo for your help!

---

<div class="post-metadata">

**Author:** ![rmilark](https://avatars.discourse-cdn.com/v4/letter/r/a9a28c/32.png) [@rmilark](https://discourse.julialang.org/u/rmilark)\
**Post date:** [November 5, 2018, 4:43am UTC](https://discourse.julialang.org/t/julia-novice-integer-programming-code-optimization-error/6926/5 "2018-11-05T04:43:52Z")

</div>

Hello yold6, I am also new to Julia and am encountering a similar method error which I believe is being caused by the same incorrect Array function call you had experienced. I am using:

fielders = Array(Int64,0)

Error message:

MethodError: no method matching +(::Type{Array{Int64,0}}, ::Type{Array{Int64,0}})

Thanks  
Mike
