Running into a deprecation while assigning variables and constraints in JuMP (v0.18.5) on Julia (0.7.0)

jump
#1

A deprecation warning is thrown when i add my variables or constraints for my optimization problem. The warning is :

┌ Warning: Deprecated syntax implicit assignment to global variable#20###368``.
│ Use global #20###368 instead.
└ @ none:0

This code used to run without any warning on Julia 0.6.2.


using JuMP, Gurobi, DelimitedFiles, PyPlot, LightGraphs, GraphPlot, Compose, Colors

@variable(IMTLP,Intermodal_shipping[i=1:n_hubs,j=1:n_hubs,m=1:n_modes,k=1:n_customers,p=1:n_products,t=1:n_echelons]>=0,Int)

@constraint(IMTLP, SDemandcon[t=1:n_echelons, g=1:n_customers, k=1:n_customers, p=1:n_products], Direct_shipping[k,g,p,t]+sum(Endhaul_shipping[j,g,k,p,t] for j in 1:n_hubs)>=Demand_specific[g,k,p,t])

How to avoid this warning??

#2

Please read the following post, and provide a minimum working example. If the warning is coming from your code, fix it. If the warning is coming from JuMP, upgrade to Julia 1.0.

2 Likes
#3
using JuMP, Gurobi

my = Model(solver=GurobiSolver())

@variable(my, x[1:2]>=0, Int)

@constraint(my, x[1] == x[2])

@objective(my, Min, x[1] + x[2])

status = solve(my)

print(my)
┌ Warning: Deprecated syntax `implicit assignment to global variable `#2781###740``.
│ Use `global #2781###740` instead.
└ @ none:0
┌ Warning: Deprecated syntax `implicit assignment to global variable `#2781###740``.
│ Use `global #2781###740` instead.
└ @ none:0
Academic license - for non-commercial use only
Optimize a model with 1 rows, 2 columns and 2 nonzeros
Variable types: 0 continuous, 2 integer (0 binary)
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [1e+00, 1e+00]
  Bounds range     [0e+00, 0e+00]
  RHS range        [0e+00, 0e+00]
Found heuristic solution: objective 0.0000000

Explored 0 nodes (0 simplex iterations) in 0.00 seconds
Thread count was 1 (of 4 available processors)

Solution count 1: 0

Optimal solution found (tolerance 1.00e-04)
Best objective 0.000000000000e+00, best bound 0.000000000000e+00, gap 0.0000%
Min x[1] + x[2]
Subject to
 x[1] - x[2] == 0
 x[i] >= 0, integer, for all i in {1,2}
#4

These warnings are in 0.7 only. The code will work as-is in Julia 1.0.

Note that when you upgrade to Julia 1.0, you will get JuMP 0.19, not 18.5. Here are the docs:
http://www.juliaopt.org/JuMP.jl/v0.19/quickstart/

Only two lines change. Your code becomes:

using JuMP, Gurobi
my = Model(with_optimizer(Gurobi.Optimizer))  # Changed
@variable(my, x[1:2]>=0, Int)
@constraint(my, x[1] == x[2])
@objective(my, Min, x[1] + x[2])
optimize!(my)  # Changed
print(my)
3 Likes
#5

ok, i didn’t know that. Thanks