# UnDefVarError - Model not defined in Julia optimization problem

**URL:** <https://discourse.julialang.org/t/undefvarerror-model-not-defined-in-julia-optimization-problem/24451>\
**Category:** General Usage\
**Tags:** question\
**Created:** [May 21, 2019, 8:12pm UTC](https://discourse.julialang.org/t/undefvarerror-model-not-defined-in-julia-optimization-problem/24451 "2019-05-21T20:12:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![RohiniShetty](https://avatars.discourse-cdn.com/v4/letter/r/f19dbf/32.png) [@RohiniShetty](https://discourse.julialang.org/u/RohiniShetty)\
**Post date:** [May 21, 2019, 8:12pm UTC](https://discourse.julialang.org/t/undefvarerror-model-not-defined-in-julia-optimization-problem/24451/1 "2019-05-21T20:12:11Z")

</div>

1. using ExcelReaders, JuMP, CPLEX, DataFrames;
2. using JuMP, Clp;
3. MinCD = JuMP.Model(solver=CPLEX.CplexSolver(CPX\_PARAM\_TILIM = 3600)); “UnDefVarError Model not defined”

I did read most of the fixes for Model not defined, I have used all those solutions yet I am facing this error in the third line of my code. Line one and two passes without any error. All my packages required are updated.  
Please help me resolve this error.  
Thank You.

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [May 21, 2019, 9:36pm UTC](https://discourse.julialang.org/t/undefvarerror-model-not-defined-in-julia-optimization-problem/24451/2 "2019-05-21T21:36:34Z")

</div>

Could you please post the complete error output? You can follow the instructions here: [PSA: how to quote code with backticks](https://discourse.julialang.org/t/psa-how-to-quote-code-with-backticks/7530) to quote your code so that it will render properly as well.

---

<div class="post-metadata">

**Author:** ![RohiniShetty](https://avatars.discourse-cdn.com/v4/letter/r/f19dbf/32.png) [@RohiniShetty](https://discourse.julialang.org/u/RohiniShetty)\
**Post date:** [May 21, 2019, 10:38pm UTC](https://discourse.julialang.org/t/undefvarerror-model-not-defined-in-julia-optimization-problem/24451/3 "2019-05-21T22:38:21Z")

</div>

![JuliaError](https://global.discourse-cdn.com/julialang/original/3X/e/1/e15e9ed474cac15769408449dbc66de8ad56c2a9.jpeg)

---

<div class="post-metadata">

**Author:** ![RohiniShetty](https://avatars.discourse-cdn.com/v4/letter/r/f19dbf/32.png) [@RohiniShetty](https://discourse.julialang.org/u/RohiniShetty)\
**Post date:** [May 22, 2019, 3:52am UTC](https://discourse.julialang.org/t/undefvarerror-model-not-defined-in-julia-optimization-problem/24451/4 "2019-05-22T03:52:22Z")

</div>

I restarted Julia, opened the file again and executed and it worked fine. Thank You.

---

<div class="post-metadata">

**Author:** ![RohiniShetty](https://avatars.discourse-cdn.com/v4/letter/r/f19dbf/32.png) [@RohiniShetty](https://discourse.julialang.org/u/RohiniShetty)\
**Post date:** [May 22, 2019, 4:09am UTC](https://discourse.julialang.org/t/undefvarerror-model-not-defined-in-julia-optimization-problem/24451/5 "2019-05-22T04:09:41Z")

</div>

I have a new error when I define my decision variables. The error message is “UndefVarError @variable not defined”  
’ ’ 'Julia  
using ExcelReaders, JuMP, CPLEX, DataFrames;

#parameters and Incides  
I = 5  
J = 5  
K = 5  
S = 5

A = ones(I,J,K,S)

#A = [[1 0 1 0 1];[0 0 1 1 0];[1 1 1 1 0];[0 1 0 0 0];[0 1 0 0 1]] #Binary Job assigned to RDSx  
PrescriptionDemand= [7;10;12] #Number of prescription processed per each RDSx  
M = 1000 #Very large number  
R = 15  
P = 30  
#V = 30  
T = 300  
Demand= [5;6;7;10;12]  
p = 10  
F = 5500

MinCD= JuMP.Model(solver=CPLEX.CplexSolver(CPX\_PARAM\_TILIM = 3600));

#DECISION VARIABLES:  
@variable(MinCD,X[1:I,1:J,1:K,1:S],Bin) **“UndefVarError @Variable not defined”**

> Blockquote Please advice. Thank You.

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [May 22, 2019, 1:22pm UTC](https://discourse.julialang.org/t/undefvarerror-model-not-defined-in-julia-optimization-problem/24451/6 "2019-05-22T13:22:26Z")

</div>

Three things.

1. You’re using JuMP 0.18 (and maybe Julia 0.6?). You should upgrade to JuMP 0.19 and Julia 1.1.

2. Close everything and restart Julia and Atom/Juno. Something is weird, but I have no idea what.

3. To quote code, you need to use backpacks ``` rather than apostrophes ‘’’
