Hello everybody!
I am trying to export only the numeric data of the result of the variable r
to a .CSV
. The model does not give an error, but I cannot export the data as I need it.
I would like the data to be written in .CSV
this way
│ Row │ value │
│ │ Int64 │
├─────┼───────┤
│ 1 │ 0 │
│ 2 │ 0 │
│ 3 │ 0 │
│ 4 │ 0 │
However it is written this way for .CSV
│ Row │ value │
│ │ String │
├─────┼─────────────────┤
│ 1 │ r:2 dimensions: │
Why can’t I export the data the way I want?
As the model is, it may not make much sense because it is a cut out of a model that I am building.
Thank you!
using JuMP, GLPK, CSV, DataFrames, GLPKMathProgInterface
Modeltest = Model(solver = GLPKSolverMIP())
a = 1:4
t = 1:4
w = 1:2
A = a
T = t
W = w
#Parameters
CR = [11, 12]
CO =[50, 51]
WA = [1, 2, 1, 2]
RHE = [150, 151]
#Variables
@variable(Modeltest,r[A,T]>=0)
@variable(Modeltest,o[A,T]>=0)
@variable(Modeltest,wr[W,T]>=0)
@variable(Modeltest,er[W,T]>=0)
@objective(Modeltest,Min,sum(CR[WA[a]]*(r[a,t]+o[a,t])+CO[WA[a]]*o[a,t] for a in A, t in T))
for w = 1:2, t= 1:4
m = @constraint(Modeltest,sum(r[a,t] for a in A) +wr[w,t] ==RHE[w])
#println(m)
end
print(Modeltest)
status = solve(Modeltest)
println("Objective value: ", JuMP.getobjectivevalue(Modeltest))
println("r = ", JuMP.getvalue(r))
valueresult = DataFrame(value=JuMP.getvalue(r))
CSV.write("C:\\Users\\raquel.santos\\Desktop\\testemodel.csv",valueresult)#CSV file path, file that has only one field called "value"