Thank you for your help @nilshg and @pyrex41 !!
Despite being able to export the data, I still haven’t been able to view it the way I need it.
Here’s the model I’m working on
using JuMP,CSV, DataFrames, GLPK, GLPKMathProgInterface, DelimitedFiles
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("wr = ", JuMP.getvalue(wr))
open("testemodel.csv", "w") do io
println(io, join([getvalue(wr[W, T])]))
#writedlm(io, join([getvalue(wr[W, T])]))
end
p = readline("testemodel.csv")
#p = readdlm("testemodel.csv")
println(p)
Perhaps I have expressed it wrongly, my question is: How to manipulate the data in an array?
espite having already used writedlm
and readdlm
, I can’t export the data to .CSV
the way I need it.
When exporting the data to .CSV
this is the answer I have:
|150.0 150.0 150.0 150.0 | 151.0 151.0 151.0 151.0|
This is the answer I would like to get, each data in a field as in a table
│ Row │ value │ value2 │
│ │ Float64 │ Float64 │
├─────┼─────────┼─────────┤
│ 1 │ 150.0 │ 151.0 │
│ 2 │ 150.0 │ 151.0 │
│ 3 │ 150.0 │ 151.0 │
│ 4 │ 150.0 │ 151.0 │