Hello everybody
Iβm still learning to program in julia and I came across this doubt. How to save data in a DataFrame using the for command?
Whenever I try to compile the last for
it displays this error message: MethodError: no method matching getindex!
Thanks
using JuMP, MathOptInterface, GLPK, GLPKMathProgInterface, CSV, DataFrames
ModeloD = Model(solver = GLPKSolverMIP())
a = 4
t = 4
w = 2
A = 1:a
T = 1:t
W = 1:w
NE = [14, 53]
WH = [2489 1447 3513 20914; 11073 5414 1523 16282]
CR = [11, 12]
CO = [50, 51]
jump_vars = Dict{Symbol, Any}()
jump_vars[:c] = @variable(ModeloD,c[A],Bin)
jump_vars[:r] = @variable(ModeloD,r[A,T] <=0)
jump_vars[:wo] = @variable(ModeloD,wo[W,T]>=0)
jump_vars[:wr] = @variable(ModeloD,wr[W,T]<=0)
jump_vars[:er] = @variable(ModeloD,er[W,T]<=0)
jump_vars[:eo] = @variable(ModeloD,eo[W,T]<=0)
jump_vars[:s] = @variable(ModeloD,s[A,T]<=0)
jump_vars[:x] = @variable(ModeloD,x[A,T]<=0)
@objective(ModeloD,Min,sum(CR[w]*(wr[w,t]+wo[w,t])+CO[w]*wo[w,t] for w in W, t in T))
for w = 1:w, t= 1:t
n= @constraint(ModeloD, er[w,t]<= NE[w])
#println(n)
end
for w = 1:w,t= 1:t
h = @constraint(ModeloD,eo[w,t]<=NE[w])
#println(h)
end
for w = 1:w,t= 1:t
Γ§ = @constraint(ModeloD,wr[w,t]+wo[w,t]==WH[w,t])
#println(Γ§)
end
print(ModeloD)
status = solve(ModeloD)
println("objective value: ", JuMP.getobjectivevalue(ModeloD))
Result = CSV.read("file.csv", DataFrame)#DataFrame creating to receive variables
#Here all variables are read
for (current_name, current_var) in jump_vars
println("$current_name = ", JuMP.getvalue(current_var))
end
#Here all variables should be exported to the DataFrame
#:resultvariable is the name of the DataFrame field that I need to fill out.
for jump_vars in CSV.File("file.csv")
Result[c,:resultvariable] = JuMP.getvalue(jump_vars[c])
end