I think your main problem is that you start from zero in W, S, and Inv. If you do this JuMP will not use an Vector, but their own special container to deal with this case, and these container keeps being used when you call getvalue.(W).
W = 1-dimensional DenseAxisArray{VariableRef,1,...} with index sets:
Dimension 1, 0:6
And data, a 7-element Array{VariableRef,1}:
W[0]
W[1]
W[2]
W[3]
W[4]
W[5]
W[6]
typeof(W) = JuMP.Containers.DenseAxisArray{VariableRef,1,Tuple{UnitRange{Int64}},Tuple{Dict{Int64,Int64}}}
┌ Warning: `getvalue` is deprecated, use `JuMP.value` instead.
│ caller = _broadcast_getindex_evalf at broadcast.jl:631 [inlined]
└ @ Core ./broadcast.jl:631
getvalue.(W) = 1-dimensional DenseAxisArray{Float64,1,...} with index sets:
Dimension 1, 0:6
And data, a 7-element Array{Float64,1}:
80.0
65.0
65.0
65.0
65.0
65.0
65.0
typeof(getvalue.(W)) = JuMP.Containers.DenseAxisArray{Float64,1,Tuple{UnitRange{Int64}},Tuple{Dict{Int64,Int64}}}
This container is not a vector and do not allow the same slicing syntax. I changed your dataframe creation to:
@show W
@show typeof(W)
@show getvalue.(W)
@show typeof(getvalue.(W))
W_=getindex.((getvalue.(W),), 1:nPeriods)
@show W_
@show typeof(W_)
H_=getvalue.(H)
L_=getvalue.(L)
P_=getvalue.(P)
C_=getvalue.(C)
S_=getindex.((getvalue.(S),), 1:nPeriods)
@show S_
@show typeof(S_)
Inv_=getindex.((getvalue.(Inv),), 1:nPeriods)
@show Inv_
@show typeof(Inv_)
#Create data frame with decision variables
decisionDF=DataFrame(W = W_, H = H_, L = L_, P = P_, C = C_, S = S_, Inv = Inv_)
Note, however, that the W_, S_, and Inv_, are normal vectors from 1:6 (they do not have the concept of zero-index). It is not a problem here but it may trip you if start doing more thing with them than just saving them to a CSV file.
I also had to fix getindex calls missing the dot in many other places (basically all calls in the file) before the whole code could run without errors. And, I had to add an using LinearAlgebra at the start of the code because dot lives in LinearAlgebra now (it comes with Julia, no extra package needed) not in the Core anymore. The same for using Statistics and the mean function. And I also had to change other line because the same problem above:
Inventory= 0.5*(getvalue.(Inv)[0] + getvalue.(Inv)[nPeriods]) + sum(getindex.((getvalue.(Inv),), 1:(nPeriods-1)))/nPeriods #average inventory
Finally, it is CSV.write not writetable.
The final code is in: Fixed JuMP Code - Pastebin.com