Yes, JuMP.value returns the value that was found by the solver.
I know it’s not in MWE format, but maybe with the full code it gets better.
I would like the N build response to be exported to the CSV I created.
using JuMP, Cbc, DataFrames, CSV
model = Model(with_optimizer(Cbc.Optimizer))
P = [12;60]
M = [0.25 0.1 0.1; 0.5 0.75 0.4]
D = [36; 22; 15]
@objective(model, Max, sum(N[i]*P[i] for i ∈ 1:2))
for i ∈ 1:3
@constraint(model, Pp*M[2*i-2+1:2*i]<= D[i])
optimize!(model) #model status
println("Objective value: ", JuMP.objective_value(model))
println("N = ", JuMP.value.(N))
for i ∈ 1:2
Result = JuMP.value.(N)
In general, you can’t appned columns to a CSV, only rows. If you are tryign to write rows to a CSV you can do
CSV.write("filename.csv", df, append=true)
I believe that for this to work df needs to be a dataframe (or other table) with the same format as what already exists in the CSV. You could for example do DataFrame(value.(N)') but this would give you the default column names :x1, :x2.
I of course don’t know the context of what you’re doing, but I suggest considering a more appropriate format for numerical data such as HDF5.jl.
I followed your suggestion, and did not reach my goal.
With this representation maybe I can better explain what I need. First I created an empty DataFrame, just with the field called QtdProduction then I made a for so that the DataFrame was only filled in the QtdProduction field with the compilation results of my model, but it’s giving error.
Results = CSV.read ("file.csv")
for i ∈ 1: 3
Results [1,: QtdAProduction] = JuMP.value. (N [i])
CSV.write ("file.csv", Results, append = true)
I made the adjustments and the code was like this:
println("N = ",JuMP.value.(N))
Results = CSV.read("file.csv";copycols=true)#I would like .CSV were filled with the answer that println()
for i ∈ 1:3
copy(Results)[i,:QtdAProduzir] = JuMP.value.(N[i])
CSV.write("file.csv",Results,append = true)
But it is not yet possible to populate .CSV with Julia’s compile result